Rsync uses the rsync algorithm to synchronize local and remote host files, which transmits only the different parts of two files for incremental backup
Characteristics:
Ability to synchronize entire directories, trees, and file systems
Selective retention of symbolic links, hard connections, file owner, permissions, devices, and time
can use rsh, SSH or port as the transmission port, support anonymous synchronization
Installation:
Yum Install-y rsync
rsync Command parameters:
-V indicates verbose detailed display
-Z means compression
-R means recursive recursion
-T means keeping the original file creation time
-O means to keep the original file owner
-p means to keep the parameters of the original file
-G means to keep the original file's owning group
-A archive mode
-P represents the option function in place of both-partial and-progress
-e SSH establishes an encrypted connection.
--progress means to show detailed progress
--delete means that if the server side deletes the file, then the client also deletes the file accordingly, maintaining true consistency.
[Email protected]::share1 user123 is the server-side designated authentication user,:: Share1 is the module name, which is the name that is customized in/etc/rsyncd.conf.
--exclude= "*.sh" does not contain some files
SSH-based synchronization source
Backup from remote server to native
Rsync-avz [Email protected]:/var/www/html/*/backup/ssh/
Uploading to a remote server from this computer
rsync-avz/backup/ssh/* [Email protected]:/var/www/html/
Synchronization source based on Rsync
Vim/etc/rsyncd.conf
address=192.168.200.102 #监听地址
port=873 #监听端口
Use Chroot=yes #是否锁定path目录
Uid=nobody
Gid=nobody
Log File=/var/log/rsyncd.log #日志位置
Hosts allow=192.168.200.0/255.255.255.0
Hosts deny=0.0.0.0/0.0.0.0
[Backup]
Comment=backup_server #说明
Path=/var/www/html #共享目录
Read Only=false #权限为读写, true read-only
List=false #不允许列出文件
Dont compress=*.gz *.bz2 *.zip #传输时那些文件不压缩
Auth users=user123 #虚拟用户用户名
Secrets file=/etc/rsyncd_users.db #虚拟用户密码配置文件位置
Vim/etc/rsyncd_users.db
user123:1234
Set password file permission to 600 (must, otherwise prompt authentication failed)
chmod 600/etc/rsyncd_users.db
Set directory Permissions
Setfacl-m user:nobody:rwx/var/www/html/
Start rsync
Rsync--daemon
Centos7 start
Systemctl Start RSYNCD
Client Testing
Backup from remote server to native
Rsync-avz [Email protected]::backup/backup/rsync/
Uploading to a remote server from this computer
rsync-avz/backup/rsync/* [Email Protected]::backup
rsync-avz/backup/rsync/* Rsync://[email protected]/backup# The same result as the above command
Password-free verification
1. SSH key login can be implemented
2. Automatic login via variable Rsync_password
Export rsync_password=1234
3. Specify the password file with--password-file=/password/path/file (permissions to 700)
Real-time Sync Tool: INotify (server installation required for backup)
https://sourceforge.net/projects/inotify-tools/
TAR-XZVF inotify-tools-3.13.tar.gz
CD inotify-tools-3.13/
./configure
Make && make install
Vim rsync.sh
#!/bin/bash
A= "/usr/local/bin/inotifywait-mrq-e create/var/www/html/"
b= "/usr/bin/rsync-avz/var/www/html/* [email Protected]:/root"
$a | While read directory event file
Do
$b
Done
chmod rsync.sh
./rsync.sh &
Export rsync_password=1234 #实现免密码验证
cd/var/www/html/
[[email protected] html]# Touch 123
[[email protected] html]# sending incremental file list
123
Sent 102 bytes Received bytes 266.00 bytes/sec
Total size was 0 Speedup is 0.00
Inotify+unsion bidirectional real-time synchronization
Environment configuration:
Two machines can access each other through key pairs
Http://liang-yao.cnblogs.com/p/8448224.html
2. Install the Unison compiler tool OCaml
wget https://caml.inria.fr/pub/distrib/ocaml-3.10/ocaml-3.10.1.tar.gz
Tar xzvf ocaml-3.10.1.tar.gz
CD OCAML-3.10.1/
./configure
Make World opt
Make install
3. Installing Unison
wget http://www.seas.upenn.edu/~bcpierce/unison//download/releases/unison-2.32.52/unison-2.32.52.tar.gz
Tar xvf unison-2.32.52.tar.gz
CD unison-2.32.52
Make Uistyle=text threads=true static=true
#当前工作模式: Text multi-process working mode
CP Unison/usr/local/bin
4. Installing INotify
https://sourceforge.net/projects/inotify-tools/
TAR-XZVF inotify-tools-3.13.tar.gz
CD inotify-tools-3.13/
./configure
Make && make install
Server2 and Server1 steps are the same
Server1 creating the Server1 directory
Mkdir/server1
Server2 Creating the Server2 directory
Mkdir/server2
5. Script: Vim 3.sh
#!/bin/bash
#server1和server2的netip和localfile, Netfile different
Netip=192.168.200.101
Localfile=/server2
Netfile=/server1
A= "/usr/local/bin/inotifywait-mrq-e create,delete,modify $localfile"
b= "/usr/local/bin/unison-batch $localfile/ssh://$netip/$netfile"
$a | While read directory event file
Do
$b
Done
chmod +x 3.sh
./3.sh & #把脚本放入后台执行, view results
!!! Host name cannot be the same
Linux Remote Incremental backup-rsync