rsync is a file transfer program for Unix systems. rsync uses the “rsync algorithm” which provides a very fast method for bringing remote files into sync. It does this by sending just the differences in the files across the link, without requiring that both sets of files are present at one of the ends of the link beforehand.
Some features of rsync include

  • can update whole directory trees and filesystems
  • optionally preserves symbolic links, hard links, file ownership, permissions, devices and times
  • requires no special privileges to install
  • internal pipelining reduces latency for multiple files
  • can use rsh, ssh or direct sockets as the transport
  • supports anonymous rsync which is ideal for mirroring

Server

rsyncd.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
usechroot = no
max connections = 20
strict mode = yes
port = 18730
timeout = 600
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
pid file = /path-of-rsync/run/rsyncd.pid
lock file = /path-of-rsync/run/rsync.lock
log file = /path-of-rsync/log/rsyncd.log
[static]
path = /path-to-upload/
ignore errors
read only = no
write only = no
list = no
hosts allow = xx.xx.xx.xx
hosts deny = 0.0.0.0/32
auth users = rsync_static
secrets file = /path-of-rsync/config/rsyncd.secrets

rsyncd.secrets

1
user:pass

start_rsync.sh

1
2
3
#!/bin/bash

rsync --daemon --config /path-of-rsync/config/rsyncd.conf

stop_rsync.sh

1
2
3
#!/bin/bash

pkill rsync

Client

rsyncd.secrets

1
pass

rsync_get.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/bash

RSYNC_HOME=/path-of-rsync
TARGET_PATH=/path-to-download

RSYNC_USER=username

REMOTE_IP=29.149.146.205
REMOTE_PORT=18730

date | tee -a ${RSYNC_HOME}/log/rsync_get.log
echo "------------------------" >> ${RSYNC_HOME}/log/rsync_get.log
echo "" >> ${RSYNC_HOME}/log/rsync_get.log

rsync -avh --delete --progress --password-file=${RSYNC_HOME}/config/rsyncd.secrets rsync://${RSYNC_USER}@${REMOTE_IP}:${REMOTE_PORT}/static ${TARGET_PATH} | tee -a ${RSYNC_HOME}/log/rsync_get.log

echo -e "\n" >> ${RSYNC_HOME}/log/rsync_get.log

本站由 panoshu 使用 Stellar 1.29.1 主题创建。
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。

访客数: 人,总访问量: 次。