Rsync installation instructions

Source: Internet
Author: User
Tags file copy rsync usage

RSYNC software introduction:
Rsync is a data image backup tool in unix-like systems. It can be seen from the software name-remote sync. Its features are as follows:
Images can be used to save the entire directory tree and file system.
It is easy to maintain the permissions, time, and soft links of the original file.
Installation without special permissions.
Optimized process, high file transmission efficiency.
You can use rcp, ssh, and other methods to transmit files. Of course, you can also use a direct socket connection.
Supports anonymous transmission for website images.

Software Download

The home address of rysnc is:
Http://rsync.samba.org/
The latest version is 2.4.6. You can choose to download from the original website:
Http://rsync.samba.org/ftp/rsync/
. You can also download rsync 2.4.6 from this site.

1. Download and install rsync

# Tar zxvf rsync-2.6.9.tar.gz
# Cd rsync-2.6.9
#./Configure -- prefix =/usr/local/rsync
# Make
# Make install
* *** RSYNC is enabled for normal RH installation, and the running file is stored in/usr/bin/rsync.

2. Configure rsync server

1. Start RSYNC
# Vi/etc/xinetd. d/rsync
Change the original YES to NO.
Service rsync
{
Disable = no
Socket_type = stream
Wait = no
User = root
Server =/usr/bin/rsync
Server_args = -- daemon
Log_on_failure + = USERID
}
Start RSYNC with the System
# Chkconfig rsync on

2. Configure/etc/rsyncd. conf (manually generated)
The parameters of rsyncd. conf are written on the top as global parameters, and the parameters of modules are written on the top.
# Vi/etc/rsyncd. conf
Global Parameters
Uid = root // the user who runs the RSYNC daemon
Gid = root // the group that runs the RSYNC daemon
Use chroot = no // do not use chroot
Max connections = 4 // The maximum number of connections is 4
Strict modes = yes // check the permission of the password file
Port = 873 // default port 873

Module Parameters
[Backup] // The Authentication Module name. You must specify
Path =/home/backup // the directory to which the image is to be created. It is indispensable!
Comment = This is a test // comments of This module
Ignore errors // ignore irrelevant IO errors
Read only = yes // read-only
List = no // column files are not allowed
Auth users = hening // The authenticated user name. If this row is not used, it indicates that the user is anonymous and has nothing to do with the system.
Secrets file =/etc/rsync. pas // table of password and user name comparison. The password file is generated by yourself.
Hosts allow = 192.168.1.1, 10.10.10.10 // allow hosts
Hosts deny = 0.0.0.0/0 // disable host
# Transfer logging = yes
Note: The following green files are automatically generated after the RSYNC service is installed.
Pid file =/var/run/rsyncd. pid // storage location of the pid file
Lock file =/var/run/rsync. lock // location of the lock file
Log file =/var/log/rsyncd. log // location where the log file is stored

3. Configure the rsync password (the path has been written in the above configuration file)/etc/rsync. pas (name can be written at will, as long as it is consistent with the above configuration file), format (one row per user)
Account: Password
# Vi/etc/rsync. pas
Example:
Hening: 111111
Permission: Because rsync. pas stores the user name and password of the rsync service, it is very important. Set rsync. pas to be owned by the root user and the permission is 600.
# Cd/etc
# Chown root. root rsync. pas
# Chmod 600 rsync. pas
3. rsyncd. motd (configuration welcome information, optional)
# Vi/etc/rsyncd. motd
Rsyncd. motd records the welcome information of the rsync service. You can enter any text information, such:
Welcome to use the rsync services!
4. Make the configuration take effect
# Service xinetd restart

3. Start rsync server

Two Methods for RSYNC server startup
1. Start the rsync server (independently started)
#/Usr/bin/rsync-daemon
2. Start the rsync server (xinetd superprocess is enabled)
#/Etc/rc. d/init. d/xinetd reload

4. Add rc. local

In various operating systems, rc files are stored in different locations and can be modified so that rsync-daemon can be loaded during system startup.
# Vi/etc/rc. local
Add/usr/bin/rsync -- daemon

5. Check rsync

# Netstat-a | grep rsync
Tcp 0 0 0.0.0.0: 873 0.0.0.0: * LISTEN

6. Configure rsync client

1. Set the password
# Vi/etc/rsync. pas
111111
Modify permissions
# Cd/etc
# Chown root. root rsync. pas
# Chmod 600 rsync. pas
2. Connect the client to the SERVER
Retrieving files from the SERVER
/Usr/bin/rsync-vzrtopg -- progress -- delete hening@192.168.0.217: backup/home/backup -- password-file =/etc/rsync. pas
Upload files to the SERVER
/Usr/bin/rsync-vzrtopg -- progress -- password-file =/root/rsync. pas/home/backup hening@192.168.0.217: backup
This command backs up all files (including subdirectories) in the local machine/home/backup Directory to the backup directory set by the backup module of rsync server (172.20.0.6.
Note that if the path ends with "/", it indicates backing up the stuff in the directory, but it does not create this directory. If it does not contain "/", it is created.
RSYNC usage:
Rsync [OPTION]... [USER @] HOST: SRC [DEST] # Back Up Files from rsync server to Local Machine
Rsync [OPTION]... SRC [SRC]... [USER @] HOST: DEST # Back Up Files from local machines to RSYNC SERVER
3. Automatic Operation
1) vi/usr/local/rsync/time. sh // create a script file
Copy the following content
#! /Bin/bash
/Usr/bin/rsync-vzrtopg -- progress -- delete hening@192.168.0.217: backup/home/backup -- password-file =/etc/rsync. pas
2) crontab-e
Add 55 ***/usr/local/rsync/time. sh // run the time. sh script file every 55 minutes
5. iptables
Iptables-a input-p tcp-s! 11.22.33.44 -- dport 873-j DROP
In this case, only the client IP 11.22.33.44 can enter this rsync server.
Command Introduction:-rvlHpogDtS
Rsync Command Parameters
-V indicates verbose details
-Z indicates Compression
-R indicates recursive Recursion
-T indicates the creation time of the original file.
-O indicates to keep the original file owner
-P indicates the parameter for retaining the original file.
-G indicates the group to which the original file belongs.
-A archive Mode
-P indicates the option function that replaces-partial and-progress.
-E create an encrypted connection through ssh.
-- Partial: prevents rsync from deleting the copied part during transmission interruption (if the transmission is interrupted during file copy, rsync's default operation is to undo the previous operation, that is, remove the copied part from the target machine.
Delete some copied files .)
-- Progress indicates that the detailed progress is displayed.
-- Delete: if the server deletes the file, the client also deletes the file to ensure true consistency.
-- Exclude does not include the/ins directory
-- Size-only: the difference between the two folders is that there are some new files in the source folder, and there are no files with duplicate names and modified names, this type of file may be omitted because the content is modified to the same size. This parameter can greatly improve synchronization efficiency because it does not need to check whether the content of files with the same name is the same.
-- Password-file: Specifies the password file, which contains the password of the user specified by the server.
In this way, you can use the password in the script without entering the verification password interactively. Note that the permission attribute of this password file must be set to only the owner-readable.
Hening@192.168.0.217: backup
Hening refers to the user specified for authentication on the server.
192.168.0.217 indicates the ip address of the server.
: Backup indicates the name of the module to be synchronized on the server;
/Home/quack/backup/$ DATE indicates the directory address of the synchronized file stored in the local machine.
/Var/log/rsync. $ DATE is the directory address of the Synchronized log files stored in the local machine.
Note:
If you do not put/, the directory name also contains mirror. If you put/, There is only mirror in the directory.
Instance summary process:
1. Configure the master Console
# Vim/etc/rsyncd. conf
###################################
Uid = nobody
Gid = nobody
Use chroot = no
Max connections = 4
Stirict modes = yes
Port = 873
[Backup]
Path =/usr/local/test/
Comment = This is a test
Ignore errors
Read only = false
List = no
Hosts allow = 192.168.0.11
Hosts deny = 0.0.0.0/0
Auth users = bakweb
Secrets file =/etc/rsyncd. pw
Pid file =/var/run/rsyncd. pid
Lock file =/var/run/rsync. lock
Log file =/var/log/rsyncd. log
###################################
# Vim/etc/rsyncd. pw
###################################
Bakweb: 123456
###################################
# Cd/etc
# Chown root. root rsyncd. pw
# Chmod 600 rsyncd. pw
Start rsync server
# Rsync -- daemon
Check whether port 873 is enabled
Join startup
# Echo "rsync -- daemon">/etc/rc. local
Write Permission to the/usr/local/test directory
# Chown-R nobody. nobody/usr/local/test
# Chmod-R 770/usr/local/test
Master configuration complete
2. Client Configuration
# Vim/etc/rsyncd. pw
####################################
123456
####################################
# Chown root. root/etc/rsyncd. pw
# Chmod 600/etc/rsyncd. pw
Then, use the command to directly update the data file on the server without the password.
Rsync-vzrtopg -- progress -- password-file =/etc/rsyncd. pw/usr/local/bin/bakweb@192.168.0.10: backup

Note:

1. the backup name here is [backup] In the master conf configuration. The backup name must be the same.
2. bakweb is the bakweb In the conf configuration of the master. You can name it as needed, not a system user.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.