This guide explains how to use Synco to push data from a server to a remote backup destination. Here is an overview:
Step 1: Server Setup
We need to make sure the backup source and destinations have all the right software installed, and we also need to create a user on the backup server which will be used for ssh access. These installation instructions should work for Debian/Ubuntu Linux; you may need to use a different package manager on other platforms.
Step 2: Enable SSH Access
On the source server (s1.example.com) we need to enable password-less SSH login to the backup server (backups.example.com):
You can test this by checking whether you can log into backup@backups.example.com without having to enter in a password. Make sure you run this test as root, as this is the account on the source server which has the appropriate keys:
Step 3: Setting up the backup script
Firstly, we need to setup a directory for the backup scripts.
Then, create the following file named /etc/lsync/server-backup.rb. You will need to update references to the various hostnames to suit your exact requirements:
Step 4: Testing the backup
You can now test the backup to ensure that it is setup correctly.
Step 5: Adding MySQL backup
It is generally not advisable to backup the working files of a database server while it is in operation. This is because the database files are constantly in use, and while the database server is running these files may not be in a consistent state. Thus, it is a good policy to dump data to a known plain text format for backup purposes.
Firstly, we need to create an account for dumping the data. You will need to log into MySQL with an account that can create users and grant permissions. Select an appropriate $password:
Once this is done, we need to update the /etc/lsync/server-backup.rb backup script:
The :prepare event for a server specifies scripts that run before the backup is executed, on either the master or target server. This means that when we run the backup, a copy of the database will be dumped into /var/backups, and this will be copied as part of the regular data backup.
Note, if you are adding sensitive information (in this case, a password for MySQL) to the configuration file, you may want to restrict access to the file. In this case, you should execute $ chmod go= /etc/cron.daily/lsync-backup, and make sure the file is owned by root (or another similar secure account).
Step 6: Integrating with cron
To ensure the backup is running automatically, you can add it into cron. This is fairly simple, simply create a file called /etc/cron.daily/lsync-backup:
Don't forget to $ chmod +x /etc/cron.daily/lsync-backup. Depending on your requirements, you might add this as an hourly job rather than a daily job.
Conclusion
This guide is a simple outline to incrementally backup a server. The basic configuration supplied will prune older backups according to the default policy (see the prune command for more details). This configuration can easily be expanded to backup the data to multiple endpoints, as required, simply by adding additional server clauses.