Custom CentOS CWP Backup Solution

Posted on Posted in Software

AutoMySQLBackup

During working with CentOS CWP 6.9, I found the built-in backup method is a little bit plain. While searching for an alternative solution, I came across AutoMySQLBackup. A very handy and simple to use tool. It only uses mysqldump which part of mysql-client. The configuration file lets the user customize the backup interval, excluded databases, backup location, backup rotations and more.

Installation

First download the package from Sourceforge unpack it:

Run the extracted install script:

It will move 2 files to the appropriate directories.

/usr/local/bin/automysqlbackup

/etc/automysqlbackup/automysqlbackup.conf

Configuration

Let’s open the configuration file with an editor.

Most important part is the correct credentials for the database connection. For that I set the username, password and the DB location.

Now the location of the database backups. I configured mine to be within the /home directory instead /var. It is important that the database and user accounts share the same parent directory (see later). By adding more and more data to the user accounts, the backups started to growing. Then my root logical volume ran out of space and the whole server crashed. To change the location I modified the following line:

You can also configure databases which are not required to be backed up.

The Rotation Settings describe the scheduling and number of backups to be kept. I wanted to do the monthly backup on the 1st of every months and keep 6 backups. So I set the monthly rotation to 150.

Keep 6 weekly backups which are run on every Fridays and the same rotation for the daily schedule.

The Backup Script

After the MySQL DB backup was set, I wanted to do the same with all the user data. User accounts can be backed up from CWP. However, it doesn’t give a good choice of options regarding the scheduling and backup rotations. The following script package gives more freedom over it. It contains 1 configuration and 2 bash files.The files can be downloaded from To make this work with AutoMySQLBaskup, I’d recommend to set the PARENT_DIR to share it with the database backup files. So if the database is backed up to /home/backup/db then the user account should be saved to /home/backup/account. In the config file it would look like this:

The full configuration file account-backup-cron.conf can be viewed below.

FTP server can be configured so all the backups will be synchronized according to the settings in the configuration. This is done by ftp-backup-cron.sh.

What does account-backup-cron.sh do?
  • Connect to MySQL database and retrieve a list of the user accounts.
  • Copy and compress the data from the accounts.
  • Synchronize the number of saved backups.
  • Do the weekly backup if it’s due.
  • Do the monthly backup if it’s due.
What does ftp-backup-cron.sh do?
  • Connect to MySQL database and retrieve a list of the user accounts.
  • Create a temporary folder where the FTP location will be mounted.
  • Connect to FTP and mount the connected location.
  • Synchronize the content of the PARENT_DIR and the number of saved backups.
  • Retrieve a list of all the existing database names from MySQL server.
  • Delete the excluded ones from the list (configured in AutoMySQLBackup).
  • Synchronize the database backups with the FTP server (daily, weekly, monthly).
  • Maintain miscellaneous folders created during backup.

The last thing I had to do was to make sure that these will run every day in a certain time. I added the followings to the Crontab.

  1. AutoMySQLBackup backups the database at 23:30.
  2. User accounts are backed up at 0:30.
  3. The parent backup directory is uploaded and synchronized via FTP at 1:30.

The timings can be various according to the server’s bottleneck.

Final Thoughts

I cannot guarantee that this solution will work on every CWP servers. Configurations could differ from the one I used to create the scripts. It has been working for me for years, however sometimes after a server update I have to tweak things.

Leave a Reply

Your email address will not be published. Required fields are marked *