rsync is a remote and fast incremental backup tool that supports local, ssh and rsync host synchronization.
rsync is one of the basic components of the default Linux/Unix system installation, so we don't need to install it manually.
[root@mysql /]# rpm -q rsync rsync-3.0.9-17.el7.x86_64
rsync programs do not have configuration files, so we need to write our own:
[root@mysql /]# vim /etc/rsyncd.conf ....... Omit part of content uid = nobody gid = nobody use chroot = yes // Imprisonment in source directory address = 192.168.1.10 // Monitoring address can be omitted port 873 // Monitor port log file = /var/log/rsyncd.log // Specify log file location pid file = /var/run/rsyncd.pid // File location where process ID is stored [mysql] // Shared module name path = /usr/local/mysql/data // The path of the source directory comment = aaaa // Description can be omitted read only = no // Whether it's read-only or not, no can read or write dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 // File types that are no longer compressed at synchronization auth users = zs // Authorized account secrets file = /etc/rsyncd_users.db // Data files for storing account information
rsync has its own account document, so it only needs to write account information in the account document.
[root@mysql /]# vim /etc/rsyncd_users.db zs:123.com // User name before password [root@mysql /]# chmod 600 /etc/rsyncd_users.db # The account is stored in clear text, so it is necessary to adjust the file permissions.
Backup users need to have corresponding access to the source directory / usr/local/mysql/data:
[root@mysql /]# chmod -R 755 /usr/local/mysql/data/ [root@mysql /]# ll -d /usr/local/mysql/data/ drwxr-xr-x 5 mysql mysql 160 Aug 21 15:15 /usr/local/mysql/data/
Start the rsync service program with the running parameter of "--daemon"
[root@mysql/]# Rsync -- daemon # boot To shut down rsync services, kill processes can be used: [root@mysql/]# kill $(cat/var/run/rsyncd.pid)# stop
Used locally:
[root@localhost /]# rsync /etc/passwd /opt/ # In this local command, the individual feels useless, as opposed to direct cp replication [root@localhost /]# rsync -rl /etc/passwd /opt/ # - r denotes recursive entire directory tree-l for backing up linked files
Download (Download):
[root@localhost backup]# rsync -avz zs@192.168.1.10::mysql /backup/ Password: // Input password //or [root@localhost /]# rsync -avz rsync://zs@192.168.1.10/mysql /backup/ Password:
Upload (Upload):
[root@localhost /]# rsync -avz /backup/ zs@192.168.1.10::mysql Password: // If backup / no, it means uploading the directory, and if it does, uploading the files in the directory.
Some common backup options for rsync:
Backup work in a real production environment is often repeated as planned, so a task plan is needed:
[root@localhost /]# vim /etc/server.pass # To avoid entering a password during synchronization, create a password file 123.com [root@localhost /]# chmod 600 /etc/server.pass # Configuration authority [root@localhost /]# crontab -e 30 22 * * * /usr/bin/rsync -avz --delete --password-file=/e tc/server.pass zs@192.168.1.10::mysql /backup [root@localhost /]# systemctl status crond.service # Ensure that the service is started ● crond.service - Command Scheduler Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled) Active: active (running) since Four 2019-08-22 00:37:47 CST; 13min ago Main PID: 1005 (crond) CGroup: /system.slice/crond.service └─1005 /usr/sbin/crond -n