Linux VPS uses Rsync to realize synchronized incremental backup of website files/server data

888u

Last update at :2024-06-19,Edit by888u

Whether we choose a virtual host, a VPS or a server, the most critical thing is the data in the server. Relatively speaking, if you choose a high-quality service provider and server, the chance of accidents will be smaller, but it is not impossible. Because server accidents are not under the control of the merchant and our users, including problems with the programs in the server, it may also be our human operation problems.

If the website data volume is not large, we can use regular manual backup or use a scheduled backup script. The one-click package environment or WEB panel has the function of automatic backup to local and remote servers. If the amount of data is large, we can actually use Rsync to implement synchronous incremental backup. The following records are implemented through Rsync to achieve file synchronization incremental backup.

The setup process is rather cumbersome. If we ordinary project users can use the merchant's own snapshot timing or the automatic backup function of the script environment, as well as our own regular backup. (This article comes from: https://www.laobuluo.com/1070.html)

First, preparations

1. Data backup

If we are not sure to get it done at once, we can prepare two test environment servers to implement Rsync synchronization backup function and then use it in the production environment. If used in a production environment, we can back up server snapshots, or back up website and project data.

2. Server preparation

Here we are using Rsync synchronous incremental backup, so we need to prepare the main server and a backup server. In view of the function after data backup, we can directly back up to a certain directory on the backup server, or install the backup server in the main server environment and back up the website projects that need to be backed up to the corresponding same directory.

3. Open port

If our server does not have iptables firewall rules set, then do not set the port. If we have set up an iptables firewall, we need to add port 873 and allow it to pass.

vi /etc/sysconfig/iptables

Open the iptables rule document and add:

-A INPUT -p tcp -m state –state NEW -m tcp –dport 873 -j ACCEPT

After editing and saving, /etc/init.d/iptables restart will take effect. In the same way, we need to set up both the main server and the backup server at the same time.

Second, configure the backup server

1. Install rsync

2. Configuration file

vi /etc/xinetd.d/rsync

Change the configuration file disable parameter from \\"yes\\" to \\"no\\".

3. Create configuration file

vi /etc/rsyncd.conf

Create the file and add the following script:

log file = /var/log/rsyncd.logpidfile = /var/run/rsyncd.pidlock file = /var/run/rsync.locksecrets file = /etc/rsync.passmotd file = /etc/rsyncd.Motd# Create a module name, which needs to be consistent [www.laobuluo.com]#Backup server directory address path = /home/wwwroot/www.laobuluo.com#corresponds to the above module name comment = www.laobuluo.comuid = rootgid = rootport = 873use chroot = noread only = nolist = nomax connections = 200timeout = 600#Create a synchronized username, choose it casually, anyway, it must be consistent when it appears later auth users = www.laobuluo.com_user#Main server IP address hosts allow = xxx.xxx. xxx.xxx

Create a file based on the actual information of our website project and server, paste it into the configuration file, save and exit.

4. Create a password pairing file

vi /etc/rsync.pass

Create a password pairing file:

www.laobuluo.com_user:1234567890passwd

The red field needs to correspond to the auth users above, and the blue part is the password we created the pairing with. The password will also be used when configuring the main server later, so it must be consistent.

5. Open permissions and startup

chmod 600 /etc/rsyncd.confchmod 600 /etc/rsync.passservice xinetd restart

Third, configure the main server

1. Install rsync

yum install rsync xinetd -y

2. Configuration file

vi /etc/xinetd.d/rsync

Change the configuration file disable parameter from \\"yes\\" to \\"no\\".

3. Create a password pairing file

Put in the blue password we have in the backup server above. It must be consistent.

4. Authorization and activation

Fourth, configure the main server

In this step, we continue to configure the main server. We need to install and configure inotify-tools to achieve synchronous incremental backup.

1. Install environment package

yum install make gcc gcc-c++ -y

2. Download and install inotify-tools

cd /usr/local/srcwget https://download.laobuluo.com/tools/inotify-tools-3.14.tar.gztar -zxvf inotify-tools-3.14.tar.gzcd inotify-tools-3.14./configure –prefix=/usr/local/inotifymakemake install

3. Configure environment variables

echo \\”PATH=/usr/local/inotify/bin:$PATH\\” >>/etc/profile.d/inotify.shsource /etc/profile.d/inotify.shecho \\”/usr /local/inotify/lib\\” >/etc/ld.so.conf.d/inotify.confln -s /usr/local/inotify/include /usr/include/inotify

4. Configuration parameters

Reference script – https://soft.laozuo.org/scripts/rsync.sh

Modify your own files and directories, then save and exit.

6. Create a list of excluded directories

vi /usr/local/inotify/exclude.list

Create an excluded directory, where you can add unsynchronized directories, one directory per line. If it is not available at the moment, you can leave it blank and add it if needed later.

7. Authorization and setting startup

chmod +x /usr/local/inotify/rsync.sh

Here we authorize.

vi /etc/rc.d/rc.local

Add the last line:

sh /usr/local/inotify/rsync.sh &

Fifth, detection and effectiveness summary

1. Checking takes effect

After setting up, we can check manually

sh /usr/local/inotify/rsync.sh &

Execute the script on the main server. If you see a directory in progress, it means it is perfect. Then go to the backup server and you can see the file directories that have been backed up.

2. Automatically take effect

Restart the main server and it will take effect automatically. If you are worried, we can drop a file in the corresponding directory of the main server to see if the backup server has been added.

To summarize, this article uses Rsync to synchronize incremental backup files on Linux VPS and servers in more detail.

Recommended site searches: Hong Kong IP proxy, free overseas server, server cost, network server, server space rental, vps server personal virtual host, registered cn domain name, virtual host evaluation, domain name registration,

Linux VPS uses Rsync to realize synchronized incremental backup of website files/server data

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码