Backup and restore database example
Backup the database tables into zip file, and restore the data from backuped zip file. In this page, how to prepare the module to back up and restore data.
By preparing this module, you can easily test the application. Test automation program will use this function.
Backing up database is very important and useful function to install, testing software. By preparing this method, you can easily test your application totally.
In addition to this method, using selenium and JUnit makes your software testing efficiently. To automate testing software is necessary method to write robust software.
By making database backup function in your application, data migration become very easy. For example, the Alinous Document CMS has database backup page in the system section. By using the function, you can download the add data archived into a single zip file.
In order to access this example, please access the url below or "Backup and restore database" link from the toppage.
Then the page below will appear.
In order to backup the database tables, push "Backup" button under the "Backup all" header. Then you can download zip file, so please save the file in the local folder.
Select the downloaded file in the Backup file. And push the recover button. Then the database tables are recovered into the status when you backuped the data.
The source code is in the "ALINOUS_HOME/samples/backup/" folder.
The implementation of "index.alns" in this folder is below.
In this source code, when the Backup button pushed, the $IN.cmd is "backup", and when the "Recover" button pushed it is "recover". And execute each function.
When you download the data, the function "backup($IN, $SESSION)" is called.
This function calls backupContents() function for each table to backup. After making the data, make zip file by calling "Zip.compress()".
The code below is the source code of backupContents().
In this function, it names the csv file for the table data, and calls "SQL.backup()".
When you download the data, the function "recover($IN, $SESSION)" is called.
This function extracts the zip file by calling "Zip.extract()" function and restore the table by calling recoverTable(). The source code of recoverTable() is below.
This example is testable code, there is more example to do testing automation. Please take a look at Testing Backup database example.