If certain files on a server are of paramount importance, setting up a mirror on another server is an excellent method for backing up data. In the event of hardware damage or network failure on the primary server, we can promptly use the mirrored files for data recovery, ensuring the applications are up and running again without delay.
Execute the following command on a Linux cloud server to install rsync.
CentOS
yum install rsync
Ubuntu/Debian
apt-get install rsync
For instance, to synchronize data from Cloud Server A to Cloud Server B, remotely access Cloud Server B and execute the following command:
rsync -avrt --delete --rsh='ssh -p 22' root@<ipa>:<source> <destination>
Here, 'ipa' is the IP address of Cloud Server A, 'source' is the source directory on Cloud Server A, and 'destination' is the target directory on Cloud Server B. If the remote port is not the default 22, modify it to the corresponding port number.
By setting up a cron job, you can automate the execution of the above rsync command, thereby achieving file mirroring.
Edit the cronjob file:
vi /etc/crontab
Add the following command to sync every 3 minutes:
*/3 * * * * rsync -avrt --delete --rsh='ssh -p 22' root@<ipa>:<source> <destination>
This concludes the method for setting up file mirroring between two cloud servers using rsync.
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58