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.

Data migration and install become easy

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.

Make Testing program easy

In addition to the install script, the database backup function makes testing automation easy. When you test an enterprise application, it have condition of the database table and data. By automating to set up the database and the data, testing automation is fully automated.

Access the example

 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.

Backup and restore database page

Download backuped data

 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.

Restore from downloaded data

 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.

Backup and restore database page's source code

 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.

Download backuped data

 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()".

Restore from downloaded data

 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.

In this code, at first, checking the file exist or not by calling "File.exists()". Next delete the data inthe table, and resotre the data from csv file, by calling "SQL.loadcsv()".

Testing automation

 This example is testable code, there is more example to do testing automation. Please take a look at Testing Backup database example.

Go to Top