How to Use Rsync for Remote Disaster Recovery Backup

         rsync is a data mirroring backup tool for Linux systems. With rsync, you can back up local system data over a network to any remote host. rsync has the following features:

      It can mirror entire directory trees and file systems.
      It supports incremental data synchronization, with highly efficient file transfer, resulting in very short sync times.
      It can preserve original file attributes such as permissions and timestamps.
       It encrypts data during transfer, ensuring data security.
    Next, we will detail rsync’s usage through an example. Let’s assume we have two Linux systems, A and B. System A runs the business services, and System B serves as a remote disaster recovery backup machine for A. In this setup, System A acts as the rsync server, and System B acts as the rsync client. rsync software needs to be installed on both A and B. Then, the rsync daemon runs on System A, while System B can periodically back up specified data from System A using the crontab daemon. This achieves remote data disaster recovery.
Our installation environment is:
Operating System: Red Hat Enterprise Linux Server release 5
Kernel Version: Linux web 2.6.18-8.el5
System A IP Address: 192.168.60.253
System B IP Address: 192.168.60.231
(1) Install rsync on both System A and System B
rysnc’s homepage is: http://rsync.samba.org/. The version we downloaded here is rsync-3.0.4, followed by compilation and installation:
[root@web ~]#tar zxvf rsync-3.0.4.tar.gz
[root@web ~]#cd rsync-3.0.4
[root@web rsync-3.0.4]# ./configure
[root@web rsync-3.0.4]# make
[root@web rsync-3.0.4]# make install
This completes the rsync installation.
(2) Configure rsync on System A
rsync’s configuration file is /etc/rsyncd.conf. After rsync is installed, this file does not exist by default, so we manually create one. The rsyncd.conf file consists of one or more module structures. The file comprises global parameters and module parameters. A module definition begins with the module name in square brackets and ends where the next module definition starts. The configured content is as follows:
uid = nobody
gid = nobody
use chroot = no
max connections = 10
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[ixdba]
path = /webdata
comment = ixdba file
ignore errors
read only = true
list = false
uid = root
gid = root
auth users = backup
secrets file = /etc/server.pass
The meaning of each option is explained as follows:
飪?uid   This option specifies the user ID that the daemon should have when transferring files for this module. The default value is “nobody”.
飪?gid   This option specifies the group ID that the daemon should have when transferring files for this module. The default value is “nobody”.
飪?max connections  This option specifies the maximum number of concurrent connections for the module to protect the server. Connection requests exceeding the limit will be temporarily blocked. The default value is 0, which means no limit.
飪?pid file This option specifies the path to the PID file for the rsync daemon.
飪?lock file This option specifies the lock file supporting max connections. The default value is /var/run/rsyncd.lock.
飪?log file  This option specifies the path to rsync’s log output file.
飪?[ixdba] Indicates the start of a module definition, where ixdba is the corresponding module name.
飪?path  This option specifies the files or directories to back up. This is required. The directory specified here is /webdata.
飪?list  This option sets whether the module is listed when a client requests a list of available modules. The default value is true. If you need to create a hidden module, it can be set to false.
飪?auth users This option defines the usernames that can connect to this module, separated by spaces or commas if multiple. It is important to note that these users have no relation to Linux system users. The user specified here is backup.
飪?secrets file  This option specifies a file containing “username:password” format entries. The username is the user defined by the “auth users” option, and the password can be arbitrarily specified, as long as it matches the secrets file on the client side. This file only takes effect when auth users is defined. The system does not have this file by default, so you must manually create one.
(3) Start the rsync daemon on System A
Execute the following command to start the rsync daemon:
[root@web ~]# /usr/local/bin/rsync –daemon
[root@localhost /]# ps -ef|grep rsync
root     20278     1  0 16:29 ?        00:00:00 /usr/local/bin/rsync –daemon
(4) Configure rsync on System B
 No settings are needed on the backup machine; you just need to execute the rsync synchronization operation. To avoid entering a password during the sync process, you need to create a secrets file on System B. The content of this file is the password for the user specified in the “auth users” option of System A’s rsyncd.conf file. The name and path of this file can be arbitrarily specified, as long as it is referenced when executing the rsync sync command.
 Next, execute the sync operation. See the following command:
[root@web~]# /usr/local/bin/rsync -vzrtopg –delete –progress [email protected]::ixdba /ixdba.net  –password-file=/etc/server.pass
The meaning of each parameter in this command is described as follows:
飪?In the “–vzrtopg” option, v stands for “—verbose”, meaning verbose mode output; z stands for “–compress”, meaning the backed-up files are compressed during transmission; r stands for “–recursive”, meaning subdirectories are processed recursively. t stands for “–times”, used to preserve file time information; o stands for “–owner”, used to preserve file owner information; p stands for “–perms”, used to preserve file permissions; g stands for “–group”, used to preserve file group information.
飪?The “–delete” option specifies that data mirroring synchronization should be based on the rsync server side, i.e., keeping the server’s directory completely consistent with the client’s directory. In this case, it means synchronizing based on server A.
飪?The “–progress” option displays the progress of the data mirror synchronization process.
飪?[email protected]::ixdba” indicates backing up the ixdba module on server 192.168.60.253, i.e., specifying the module to back up. backup means using the user “backup” to back up this module.
飪?“/ixdba.net” specifies the storage path for backup files on the client machine, meaning the backed-up files will be stored in the /ixdba.net directory on the backup machine.
飪?“–password-file=/etc/server.pass” specifies the location of the password file stored on the client machine. This way, no interactive password input is required when executing the sync command on the client. Note that the name and location of this password file can be arbitrarily specified, but the file must exist on the client machine. The file content is solely the backup user’s password, which here refers to the password for backup.
Actually, rsync, as a client tool, provides many options and parameters. We have only listed some commonly used ones here. For more detailed information, please execute “man rsync”.
If the configuration is correct, rsync will automatically synchronize the data to be backed up from the server (System A) to the client (System B). After the rsync command completes the data synchronization on the client, it will stop automatically. Later, if new data is added to the server directory, the client will not automatically

Leave a Comment

Your email address will not be published.