A. Environmental and test instructions
rsync (remote sync) data mirroring and software under unix unix-platform, it is not as required full backup FTP, rsync the change may be differential backup data, thereby reducing data traffic to improve efficiency
rsync configuration file is divided into three, namely rsyncd.conf (main profile), rsyncd.secrets (password file), rsyncd.motd (file server information)
The present document is a machine 2 will be described Liezi
pc1, IP: 192.168.0.230, as rsync server, you need to configure file rsyncd.conf
pc2, IP: 192.168.0.234, as rsync client that no rsyncd.conf configuration, the file may be empty
Creating / common directory on the server as a shared directory, copy some files into the directory test, test
yum -y install rsync #centos installed by default
mkdir /common; cp /etc/init.d/* /common/
II. The main configuration file description
vim /etc/rsyncd.conf
motd file = /etc/rsyncd.motd # Set prompt file server information, write a message in this file
Open transfer logging = yes # logging data transmission rsync
log file = /var/log/rsyncd.log # Set the log file name, the log format can be set through the log format parameters
pid file = /var/run/rsyncd.log # Set the rsync daemon number to save the file name
lock file = /var/run/rsync.lock # set the lock file name
port = 873 # server listens on port number, the default is 873
address = 192.168.0.230 # Set this server is listening network interface ip address
uid = nobody # Set account name or ID number when used for data transmission, default nobody
gid = nobody # set the group name or GID number when used for data transmission, default nobody
# If it is yes, rsync will chroot the first set, the root path is mapped in the parameter path below, the client, the root system is the path parameters specified path. But doing so requires root privileges, and only synchronizes name, does not synchronize the contents of symbolic links when synchronizing data.
use chroot = no
read only = yes # whether to allow clients to upload data, yes is not allowed
max connections = 10 # Set number of concurrent connections, 0 indicates unlimited
[Common] # custom module name, the rsync directory defined by the synchronization module, the plurality of defined
comment = web content # define string of notes
Really path = path / common # synchronize the directory specified by path
ignore errors # ignore IO errors
A directory can not synchronize data at #exclude = test / #exclude specify common directory
auth users = tom, jerry # is provided to allow connection to the server account, this account may not be present in the system user
secrets file = /etc/rysncd.secrets # password authentication file name, the file is read-only permission requirements, the proposed 600, only valid after setting auth users
hosts allow = 192.168.0.0/255.255.255.0 # which hosts the data set can be synchronized, multi-ip and separated by spaces between the segments
hosts deny = * # hosts allow addition to the host defined, reject all other
When the list = false # client request list display module, the module name is displayed, the default is true
III. Create a password file, firewall settings, the client and the server you have to do the following operation
echo “tom:123” > /etc/rsyncd.secrets
echo “jerry:123” >> /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets
echo "welcome to access"> /etc/rsyncd.motd # client does not need to do this
rsync --daemon # --daemon represent the background, the client does not need to open the rsync options -daemon
echo "/ usr / bin / rsync --daemon" >> /etc/rc.local # boot rsync service
firewall-cmd --permanent --add-port = 873 / tcp # add firewall rules allow access to the data port 873
IV. The client sync data
yum -y install rsync
rsync -vzrtopg --progress [email protected] :: common / test # specified through common module / files in the directory are copied to the common / test directory this client
Parameter Description
v: Show Details
z: during transmission of data compression
r: Recursive
t: retention time attribute modification
o: keep the file owner attribute
p: preserve file permissions attributes
g: file belongs to retain the property group
a: archive mode, the main preserve file attributes, equivalent to -rlptgoD
-progress: displays progress information data transmission
-password-file = FILE: Specifies the password file, the password is written to the file, to achieve non-interactive data synchronization, the file name also need to modify permissions to 600
-delete: Delete those files that exist only in the destination path (source path does not exist), data synchronization script is often coupled with this parameter
-list-only: only list server list module requires rsync server settings list = true
Five. Rsync syntax, SRC represents the source path, DEST indicate the target path
- Local Copy
rsync [options] SRC ... [DEST]
- Copy via remote shell
Download Data: rsync [options] [user @ a] HOST: SRC ... [DEST] # user @ without representation landed remote host to download data to a local root user's path DEST
Upload data: rsync [options] SRC ... [user @] HOST: DEST # here SRC represents local data, DEST represents the remote host directory
- Copy via rsync process
Download Data
rsync [options] [user @] HOST :: SRC ... [DEST] # SRC here after the double colon indicates that the module name of the remote server-side
rsync [options] rsync: // [user @] HOST [: port] / SRC ... [DEST] # SRC here represents the actual name of the directory synchronization, this way you can specify a port
upload data
rsync [options] SRC ... [user @] HOST :: DEST # Upload local client data to a remote server DEST module name specified path
rsync [选项] SRC…rsync://[user@HOST[:port]/DEST
Some examples
-
rsync -t * .c 192.168.0.54:src/ # .c file to the end of the assignment to the next 192.168.0.54 src directory under the current directory of the machine
-
rsync -avz 192.168.0.54:src/bar / data / tmp # will be copied from the host 192.168.0.54 src / bar directory recursively to the machine / data / tmp directory
-
rsync -avz 192.168.0.54:src/bar/ / data / tmp # and the difference of Example 2 is away / bar created directory data / tmp directory
-
rsync -avz / src / foo / dest # native copy / src / foo directory to / dest directory
-
rsync -avz [email protected] :: common / test3 # tom accounts using the rsync daemon to connect to remote host 192.168.0.230, the path defined by a path common module downloaded to the local directory test3
-
rsync -avz 192.168.0.230::common / test3 # anonymous download 192.168.0.230 common server module to the local / test3 directory
-
rsync --list-only [email protected] :: # server 192.168.0.254 show all the module names, you need to configure the server list = true will be displayed
-
Connect to the server each time the client needs to enter the password a lot of trouble, you can create a password file rsync.pass, in which contains a password, and then use the -password-file Specify this file
echo "123"> rsync.pass # server user password tom
rsync -avz --delete --password-file=rsync.pass [email protected]::common /dest
VI. Write simple shell scripts, so that the client data regularly to rsync server (192.168.0.230) to backup
#!/bin/bash
export PATH=/bin:/usr/bin:/usr/local/bin
SRC = common # module name
DEST = / data
server=192.168.0.230
user=tom
passfile=/root/rsync.pass
#if the DEST directory not found, then create one
[ ! -d $DEST ] && mkdir $DEST
[ ! -e $passfile ] && exit 2
rsync -az --delete --password-file=$passfile {server}::$SRC (the Y Data +% m%% D) plus # Date
After adding the timing script to perform this task
VII. Additional
Rsync can do on ubuntu synchronization reference https://www.linuxidc.com/Linux/2016-08/134584.htm