LINUX system uses software to synchronize data offsite (disaster recovery)
Published: 2023-09-14
rsync is a data mirroring backup tool under Linux. Using the fast incremental backup tool Remote Sync allows remote synchronization, supports local copying, or synchronization with other SSH and rsync hosts
1. BT Panel environment:
Supported by the BT Panel software store,Refer to: https://www.bt.cn/bbs/thread-98022-1-1.html
2. Other environments:
Implementation tool: lsyncd
lsyncd combines inotify + rsync. Lsyncd monitors the local directory tree event monitor interface (inotify or fsevents). It aggregates and combines events for a few seconds,
then spawns one (or more) process(es) to synchronize changes.
1. Installation (lsyncd is based on rsync and requires rsync >= 3.1):
# Check the rsync version
# rsync -v

1.1,Only if rsync< 3.1, execute the following; if rsync >= 3.1, skip 1.1 this step and proceed directly to 1.2
#Check the current rsync version
rsync -v
#If the version is too low, uninstall it directly
yum -y remove rsync
#Download the rsync source code
wget http://soft.xiaoz.org/linux/rsync-3.1.3.tar.gz
#Extract
tar -zxvf rsync-3.1.3.tar.gz
#Enter the directory
cd rsync-3.1.3
#Compile and install
./configure
make install
Finally, enter rsync -v again to check whether the version has been upgraded successfully
1.2 Update the EPEL repository
yum -y install epel-release
1.3 Install lsyncd
#Install lsyncd
yum -y install lsyncd
#Check the lsyncd version
lsyncd --version
#The configuration file is located at /etc/lsyncd.conf -- is the comment character
2. Configuration
2.1 Configure passwordless login
If you want to synchronize data from primary A: 192.168.0.1 to backup B: 192.168.0.2, primary A: 192.168.0.1 must have passwordless login permission to backup B: 192.168.0.2. This can be done by setting up key-based login. Only two commands are needed. The following commands are executed on primary A: 192.168.0.1:
#Generate the key file
ssh-keygen -t rsa
#Copy the public key to server B. -p specifies the SSH port. Enter the password to log in and copy.
Bssh-copy-id root@192.168.0.2 -p 22000
#Test
ssh root@192.168.0.2 -p 22000
2.2 Configure lsyncd
2.2.1 Explanation of some parameters
settings is the global configuration. Some parameters are as follows:
logfile: log file path
statusFile: process path
insist: continue running even if there is a failed target.
statusInterval: how many seconds to write to the file, default is 10s
sync is the synchronization configuration. Some parameters are as follows:
source: local file directory
host: remote server address
targetdir: remote target directory
port: SSH port of the current host, default is 22000
2.2.2 Configuration file
vi /etc/lsyncd.confEdit the configuration file, comment out or delete the default last line, and then add your own configuration
settings {
logfile = "/tmp/lsyncd.log",
statusFile = "/tmp/lsyncd.status",
insist = true,
statusInterval = 10
}
sync {
default.rsyncssh, source="/home",
host="192.168.1.2",
targetdir="/home",
rsync = {
archive = true,
compress = false,
whole_file = false
},
ssh = {
port = 220000
}
}
Continue to enter the command lsyncd -nodaemon /etc/lsyncd.conf to run and check whether there are any errors. If there are errors, check and modify according to the error situation.
If there are no errors, exit and then enter the command: systemctl start lsyncd to start lsyncd.
Related commands:
#Start
systemctl start lsyncd
#Stop
systemctl stop lsyncd
#Restart
systemctl restart lsyncd
#Set to start automatically at boot
systemctl enable lsyncd
Windows system uses software for offsite data synchronization (disaster recovery)
Linux system uses software for offsite data synchronization (disaster recovery)
Cn2 line anomaly using Nginx reverse proxy disaster recovery solution
