Rsync is a fast incremental file transfer tool. It can be used for internal backup of the same host. We can also use it as a network backup tool for different hosts. This article mainly describes how to use an rsync server to implement file transmission, backup, and mirroring. Compared with tar and wget, rsync also has its own advantages, such as fast, secure, and efficient;
Manual:
First, you need to establish the public key and key between the two servers, so that you do not need to enter the password every time, you can also achieve automatic.
You can first use rpm-qa | grep rsync to check whether rsync has been installed, software download Rysnc Home Address: http://rsync.samba.org/
Test environment in this test (2 servers, one server, and one client)
Ip address of the rsync server: 192.168.48.60
Ip address of the rsync client: 192.168.48.148
-----------------------------------------------
Configure the server first:
1. Install the rsync package
# Rpm-q rsync
Rsync-2.6.3-1
2. rsync only uses one configuration file:/etc/rsyncd. conf. This file is generally unavailable, so you can build it yourself.
# Vi/etc/rsyncd. conf
Uid = nobody
Gid = nobody
Max connections = 200
Timeout = 600
Use chroot = no
Read only = yes
Pid file =/var/run/rsyncd. pid
Host_allow = 192.168.48.148 // write the IP address of the client here
# Syslog facility = local7
# Log file =/var/log/rsyncd. log
# Rsync config
# The 'standard' things
[Rsync_gmmold] // defines the synchronization path (the client uses this keyword to link)
Path =/home // path to be synchronized
Comment = gmmold // unknown for the moment
3. Start the service
#/Usr/bin/rsync -- daemon finally starts rsync on the server as a daemon. rsync starts at Port 873.
4. Add to boot
Echo "/usr/bin/rsync -- daemon">/etc/rc. local
5. Start during rsync check
# Ps-ef | grep rsync
6. Stop the service
# Kill 'cat/var/run/rsyncd. Pi'
The configuration of the client is as follows:
1. Install the rsync package
[Root @ rhel403 old] # rpm-q rsync
Rsync-2.6.3-1
2. synchronize with the server:
# Rsync-ave ssh root@192.168.48.60:/home // home/ganfic/laji // Back Up Files under/home of the 60 host to/home/ganfic/laji/
Automatic Backup synchronization:
1. Create a B. sh file under tmp
# Vi/tmp/B. sh
Write the following content into it
#! Bin/sh
Rsync-ave ssh root@192.168.48.60:/home // home/ganfic/laji/
: Wq
Step 2 involves crontab. Enter
# Crontab-e
Then run *** sh/tmp/B. sh // ***** represents every minute, and then sh/tmp/B. sh indicates running B. sh script (which I will add below).-e uses the environment variable EDITOR or the EDITOR specified by RVISUAL to edit the crontab file. The newly created crontab file will be placed in the/var/spool/cron directory. The file name is the user name. After using cd/var/spool/cron, you will see the user file, then, use vi root (I am under the root user) to view *** sh/tmp/B. sh has been transferred here.
This completes, and then you can check whether the log file is running. Open the log file and check whether the log file is running in # vi/var/log/cron, before using the automatic operation, we manually copied the files in the/home directory of the 60 host, in the/home/ganfic/laji folder of the local machine, we will see the content of/home under the 60 hosts and delete all the content, then, let's see if we can add the content again in one minute. If there is one, it will be successful.
Linux Firewall uses iptables, so we should at least let the defined rsync server port pass through on the server side, and the client should also pass through.
Iptables-a input-p tcp-m state -- state NEW-m tcp -- dport 873-j ACCEPT
Start rsync:
/Usr/bin/rsync -- daemon -- config =/etc/rsyncd. conf
$ Rsync_HOME/rsync -- daemon -- config =/etc/rsyncd. conf
Supplement:
Rsync knowledge:
Rsync command usage
After configuring the rsync server, you can issue the rsync command from the client to implement various synchronization operations. Rsync has many functions. The following describes common options:
The Command Format of rsync can be:
1. rsync [OPTION]... SRC [SRC]... [USER @] HOST: DEST
2. rsync [OPTION]... [USER @] HOST: SRC DEST
3. rsync [OPTION]... SRC [SRC]... DEST
4. rsync [OPTION]... [USER @] HOST: SRC [DEST]
5. rsync [OPTION]... SRC [SRC]... [USER @] HOST: DEST
6. rsync [OPTION]... rsync: // [USER @] HOST [: PORT]/SRC [DEST]
From Li Changchun's blog