Langkah Pertama :
Masukkan Source Code Dibawah ini kedalam editor yang mas bro punya.
<!---
Back 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="#arguments.dbsource#" table="#Table_Name#" name="qryTableFields" type="columns" />
<cfset data[Table_Name].schema = qryTableFields />
<cfquery name="getData" datasource="#arguments.dbsource#" 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>
Back 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="#arguments.dbsource#" table="#Table_Name#" name="qryTableFields" type="columns" />
<cfset data[Table_Name].schema = qryTableFields />
<cfquery name="getData" datasource="#arguments.dbsource#" 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>
Lalu Simpan Source Code ini dengan nama file yang berakhiran ".cfm" misalkan "BackupDatabase.cfm" kedalam direktori wwwroot Coldfusion yang sudah terinstal.
Langkah Kedua :
Masukkan Source Code Dibawah ini kedalam editor yang mas bro punya (Masih didalam file "BackupDatabase.cfm").
<cfoutput>
<cfsetting showdebugoutput="no">
#BackupDatabase("darwanlns.com")#
</cfoutput>
<cfsetting showdebugoutput="no">
#BackupDatabase("darwanlns.com")#
</cfoutput>
Keterangan :
darwanlns.com = Nama Datasource yang sudah dibuat di Coldfusion
Langkah Ketiga :
Untuk Menjalankan Source code yang sudah mas bro punya, mas bro ketikkan saja alamat di browser mas bro misalkan.
http://localhost:8500/BackupDatabase.cfm
Contoh Filenya bisa di download disini Backup Database
Selamat Mencoba Mas Bro :)
Tidak ada komentar:
Posting Komentar