Use Rsync+cwRsync to achieve data backup + off-site backup

Use Rsync+cwRsync to achieve data backup + off-site backup

Background description:
The company has more than ten servers, including database, application server, FTP server, file sharing server, including windows Server server, Linux server, considering data security!
In order to achieve the purpose of data backup, we first perform data backup in the same local area network, and then realize the remote backup of data on the basis of different machines. We use Linux for the server, and Windows Server data synchronization. We use rsync+cwRsync to realize file synchronization backup, Linux- linux uses rsync!

1. What is rsync
sync, remote synchronize As the name suggests, it is a software that realizes the remote synchronization function. It can maintain additional information such as the permissions, time, soft and hard links of the original files while synchronizing files. rsync is a fast method of synchronizing files between client and remote file server using the "rsync algorithm", and can transfer files through ssh, so its confidentiality is also very good, and it is also free software.

rsync includes the following features:
Ability to update entire directories and trees and file systems
Optionally maintain symbolic links, hard links, file ownership, permissions, devices, time, etc.
There are no special permission requirements for installation
For multiple files, the internal pipeline reduces the delay of file waiting
Can use rsh, ssh or direct port as input port
Supports anonymous rsync synchronization of files, ideal for mirroring

Second, build an rsync server on Linux
①, install rsync server

yum -y install rsync
systemctl enable rsyncd
systemctl start rsyncd

View service status

[root@Data-Backup ~]# systemctl status rsyncd
● rsyncd.service - fast remote file copy program daemon
   Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-12-01 09:58:47 CST; 30min ago
 Main PID: 31454 (rsync)
    Tasks: 1
   Memory: 5.2G
   CGroup: /system.slice/rsyncd.service
           └─31454 /usr/bin/rsync --daemon --no-detach

Dec 01 09:58:47 Data-Backup systemd[1]: Started fast remote file copy program daemon.

②, modify the rsync server-side configuration file
rsync mainly has the following three configuration files: rsyncd.conf (main configuration file), rsyncd.secrets (password file), rsyncd.motd(rysnc server display information)

[root@Data-Backup ~]# cat /etc/rsyncd.conf 
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = nfsuser #rsync starts the user, the owner of the directory for synchronization backup needs to be changed to this user, otherwise it will report that there is no permission!
gid = nfsuser #rsync group
use chroot = yes
# max connections = 4
pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
log file = /var/log/rsyncd.log
port = 5286  #Modify the default port of rsync, and try not to use the default port for safety reasons!
# [ftp]
#        path = /home/ftp
#        comment = ftp export area
[bakup-11]
   path = /opt/nfs_data/test/172.16.1.11/jenkins  #backup directory
   comment = k8s_11
   read only = no
   list=no
   auth user= creditroot  #Authenticated user
   hosts allow = 172.16.1.11 #IP addresses allowed to connect

③. Create an account password file and grant 600 permissions!

[root@mirror ~]# cat /etc/rsyncd.secrets 
creditroot:************
slieoruser:************

④. Create a synchronous backup directory, and modify the owner to be the user set in the configuration, the standard is nfsuser

[root@mirror ~]# mkdir -p /opt/nfs_data
[root@mirror ~]# chown -R nfsuser:nfsuser /opt/nfs_data/ #Change folder owner

3. Download and configure cwRsync as a windows data synchronization backup client
Baidu network disk has been uploaded
Link: https://pan.baidu.com/s/1MvDZM0E6CcQp7vpPMcsu9w
Extraction code: bahc
After copying this content, open the Baidu SkyDrive mobile App, which is more convenient to operate.

Or download from the official website https://www.itefix.net/cwrsync

It is more convenient to create a new bat script to perform rsync synchronization!

D:\Soft\cwRsync\rsync -avz --port=5286 --progress /cygdrive/d/Services --bwlimit=1000 --password-file=/cygdrive/d/Soft/cwRsync/rsync.ps creditroot@10.20.11.127::bakup-123
#software catalog   
#D:\Soft\cwRsync\rsync
#Synchronization parameters
# -avz
#Sync port 
# --port=5286 If it is the default port, it can be removed!                  
#Local directory that needs to be synced
#/cygdrive/d/Services
#Sync Authentication Password
#--password-file=/cygdrive/d/Soft/cwRsync/rsync.ps
#Sync authenticated user, rsync server address, sync module name
#creditroot@10.20.11.127::bakup-123

The above software is downloaded, the password file is configured, and the bat script can be run to see the effect!
In order to achieve the purpose of regular backup, you can add a schedule to perform synchronous backup regularly through the window task plan.
About adding a task plan to customize the execution of bat scripts under windows, please refer to: https://blog.csdn.net/qq1049/article/details/78676504

Fourth, linux installs rsync as a backup client

①, install rsync

yum -y install rsync

②, also as a client, you only need to create a new password file and give 600 permissions

[root@mirror ~]# cat /etc/rsyncd.secrets 
creditroot:************
slieoruser:************

3. Pull files from rsync to the local server

rsync -avz --password-file=/root/passwd  admin@192.168.204.130::common /tmp

④, synchronize the backup of local files to the rsync server

rsync -avz --port=5286 --password-file=/etc/rsyncd.secrets /opt/nfs_data creditroot@192.168.204.130::backup-production

Log in to the rsync server to check whether there are files in the backup directory. The above is to achieve the purpose of data backup.

Five, off-site backup
This step is very simple, buy a server on Alibaba Cloud and install rsync as the server side, and synchronize the backup data of the backup server to Alibaba Cloud for off-site backup!

Tags: Operation & Maintenance

Posted by mykg4orce on Thu, 05 May 2022 04:45:51 +0300