rsync is an ideal tool to synchronize a directory tree from a primary to a secondary virtual machine. rsync efficiently detects changes in the directory tree in the primary system then compresses and copies those changes on the secondary system, where they are re-assembled. rsync is a standard tool on many Linux systems, including the Linux images in the SmartCloud Enterprise image catalog. It can use SSH to copy the files for security over the Internet. This can be a very useful technique for data back, for synchronizing file systems in high availability scenarios, or for workload migration.
We can use rsync in a scenario like this:
- Setup a database system on the primary server
- Create a database
- Create tables and add records
- Use rsync to copy the database files.
- Access the database records in the secondary system.
- Add more data to the primary database, synchronize, and access the new data on the secondary.
Here is an example of basic use of rsync to synchronize or do a fresh copy of a directory tree from a primary system to a secondary. Execute the command from the primary server.
$ rsync -avz -e "ssh -i .ssh/<mykey>" /home/idcuser/<my_directory> idcuser@<secondary_server>:/home/idcuser
In this command we use the SSH key <mykey>, located in the directory .ssh. The ssh part of the command is enclosed in double quotes to retain the SSH options. The directory tree <my_directory> will be copied to the <secondary_server> under the idcuser's home directory. if you add more data to the primary server and then execute the command again only the changes will be sent across. The base operating system images in the SCE image catalog are set-up with good defaults for using rysnc over SSH, including disallowing root access and requiring an SSH certificate instead of a password. You can also set up a cron job to automate synchronization of data. Since the SCE images disallow use of a password for SSH connections it is straightforward use it in cron jobs.