CFLib.org – Common Function Library Project

backupDatabase(dbsource)

Last updated January 8, 2013

author

Darwan Leonardo Sitepu

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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson