backupDatabase(dbsource)
Last updated January 08, 2013
Version: 1 | Requires: CF8 | Library: DatabaseLib
Description:
Backs up a database to a zip file.
Return Values:
Returns a string.
Example:
<cfoutput>
<cfsetting showdebugoutput="no">
#BackupDatabase("darwanlns.com")#
</cfoutput>
Parameters:
Name | Description | Required |
---|---|---|
dbsource | DNS. | Yes |
Full UDF Source:
<!---
Backs up a database to a zip file.
@param dbsource DNS. (Required)
@return Returns a string.
@author Darwan Leonardo Sitepu (dlns2001@yahoo.com)
@version 1, January 8, 2013
--->
<cffunction name="backupDatabase" returnType="string" output="false">
<cfargument name="dbsource" type="string" required="true">
<cftry>
<cfdbinfo datasource="#arguments.dbsource#" name="tables" type="tables" />
<cfsilent>
<cfset data = StructNew() />
<cfloop query="tables"> <!--- grab all data from table --->
<cftry>
<cfset data[Table_Name] = StructNew() />
<cfdbinfo datasource="#datasource#" table="#Table_Name#" name="qryTableFields" type="columns" />
<cfset data[Table_Name].schema = qryTableFields />
<cfquery name="getData" datasource="#datasource#" debug="no" cachedwithin=#CreateTimeSpan(0,0,0,10)# >SELECT * FROM [#Table_Name#]</cfquery>
<cfset data[Table_Name].data = getData />
<cfcatch></cfcatch>
</cftry>
</cfloop><!--- Now serialize into one ginormous string --->
</cfsilent>
<cfwddx action="cfml2wddx" input="#data#" output="packet" /><!--- file to store zip --->
<cfset zfile = expandPath("./data.zip") /><!--- Now zip this baby up --->
<cfzip action="zip" file="#zfile#" overwrite="true"><cfzipparam content="#packet#" entrypath="data.packet.xml" /></cfzip>
<cfreturn "I retrieved #tables.recordCount# tables from datasource #datasource# and saved it to #zfile#.">
<cfcatch>
<cfreturn "Backup Database Is Failed..">
</cfcatch>
</cftry>
</cffunction>
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016