5.3-Nano: Database Backup
5.x-Nano: Introduction | Cron | DtDNS | Database Backup | msmtp
|
|
Uniform Server and Database Backup
Uniform Server's database backup allows for either manual or periodic backups. Each database is extracted from the MySQL server in SQL format and compressed using 7z. These are then archived into a single file (7z).
Archive files consist of a base name (changeable) with a time stamp appended. These are saved to folder UniServer\db_backup\archive (automatically created).
Archive files can become large (they eat disk space). To minimise this, the archive folder implements a FIFO (first in first out) deletion. The total number of files is user specified. On reaching this value the eldest file is deleted to make way for a new archive file.
The above applies to both manual and automatic updates.
Database Backup Configuration
Edit the following file: UniServer\plugins\db_backup\db_backup.ini
Default settings as shown below:
Fifo = 6 ; How many archive files to save. Archive_name = dbs_ ; Archive name (a timestamp will be added) Excludes[] = information_schema ; Do not remove |
Explanation:
Fifo = 6 | This defines total number of archives to save. When limit is reached, eldest archive is deleted to
make way for a new archive. Fifo stands for first in first out (deleted) | |
Archive_name = dbs | This is a prefix of an archive’s name. A timestamp is added; for example: dbs_2009-09-26-18-56-32.7z | |
Excludes[] = db_name | If you wish to exclude databases from being backed up, add each one to the list with format shown.
The fist in this list is information_schema. It is a built-in virtual database which cannot be archived, so it is excluded. Example: To exclude databases fred123 and books. List as follows:
|
Notes:
Fifo size is a compromise between database size, disk space and how often backups are required.
Six was only a test value and should be changed to suit your particular requirements.
Running Database Backup Script
Manual Update
You can run the following batch file to manually force a backup:
Batch file: UniServer\plugins\db_backup\Run_db_backup.bat
Cron - Automatic backups
Cron provides a periodic tick to automatically run scripts. The database backup script has been pre-configured in Cron, however it is disabled by default.
To enable db_backup, edit file UniServer\unicon\main\cron.ini
Locate the db_backup block:
;[db_backup] ;start = 2009-09-21 2:56:52 ;period = hourly ;path = ..\..\plugins\db_backup\db_backup.php ;ref = |
Uncomment to enable shown below:
[db_backup] start = 2009-09-21 2:56:52 period = hourly path = ..\..\plugins\db_backup\db_backup.php ref = |
The current time will be used as the start time unless you change it to a future time. Since the start time in the example has passed, when Cron is started, db_backup will run immediately and run every hour thereafter.
You can change the period to suit your specific requirements.
Note:
You need to start Cron either manually or automatically. Refer to Cron page for details.
Logging
Logging is enabled by default. Log file: UniServer\db_backup\db_backup.log
To disable/enable logging, edit file: UniServer\plugins\db_backup\db_backup.php
Change the following line as required:
$logging = true; // true = Enable logging false = disable logging |
Extracting Files from Archive
Background 7z was chosen because of its impressive compression and provides a 7-Zip Standalone Console application 7za.exe.
Of real importance is that it is fully portable.
To extract archive files you require 7-Zip Portable. This can be found on PortableApps website
Download 7-Zip Portable from the following page:
(http://portableapps.com/apps/utilities/7-zip_portable)
The advantage of using 7-Zip Portable is it allows you to view the archive content and to extract a single database if you wish.
Warning
To ensure that archived data can be retrieved and installed, always perform several test runs. Create a duplicate server and check that backups from the prime server can be installed on this server.
You don’t want any unexpected surprises when a backup becomes essential.
Summary
The script is not written in stone, so change it as you require.
Next page covers configuring msmtp, an SMTP client now integrated into Uniform Server.