Rsync - File Synchronization
Rsync is an open source utility that provides fast incremental file transfer, making good use of delta encoding to reduce the amount of data transferred. In daemon mode, rsync listens on port 873 and transfers files over the rsync protocol. In ssh mode, files are transferred over the ssh protocol.
Installation
apt-get install rsync
Configuration
Server side
vi /etc/rsyncd.conf
#motd file=/etc/motd
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
#syslog facility=daemon
#socket options=
[ftp]
comment = public archive
path = PATH
use chroot = yes
# max connections=10
lock file = /var/lock/rsyncd
read only = no
list = yes
uid = nobody 和目录属主保持一致
gid = nogroup 和目录属组保持一致
# exclude =
# exclude from =
# include =
# include from =
auth users =
secrets file = /etc/rsyncd.secrets
strict modes = yes
hosts allow = ip地址
# hosts deny =
ignore errors = no
ignore nonreadable = yes
transfer logging = no
# log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.
timeout = 600
refuse options = checksum dry-run
dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz
vi /etc/rsyncd.secrets
user:userpasswd
chmod 600 /etc/rsyncd.secrets
service rsync start
Client side
vi /etc/rsyncd.secrets
userpasswd
chmod 600 /etc/rsyncd.secrets
Syntax
本地同步:
rsync [OPTION...] SRC... DEST
通过远程 ssh:
Pull:
rsync [OPTION...] [USER@]HOST:SRC... DEST
Push:
rsync [OPTION...] SRC... [USER@]HOST:DEST
通过 rsync 服务器:
Pull:
rsync [OPTION...] [USER@]HOST::SRC... DEST
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... DEST
Push:
rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
-r recursively sync directories
-l preserve symlinks
-p preserve file permissions
-t preserve file modification times
-g preserve file group ownership (if the user running rsync is not a superuser, group ownership is only preserved if the invoking user is a member of the source file’s group)
-o preserve file owner (super-user only)
-D preserve device files and special files (super-user only)
-a archive mode, equivalent to -rlptgoD
-v verbose output
-z enable compression
–compress-level=NUM explicitly set the compression level
-P show progress and support resuming interrupted transfers
-e use ssh, with ssh syntax
-H preserve hard links
-L when a symlink is encountered, sync the file it points to rather than the symlink itself
-u skip files that have been modified on the destination
–delete delete files on DEST that don’t exist on SRC