backupDatabase(dbsource)
Last updated February 21, 2011
Version: 1 | Requires: ColdFusion 8 | Library: DataManipulationLib
Description:
Backs up a database to a zip file.
Return Values:
Returns a string.
Example:
<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, February 21, 2011
--->
<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
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)