rsync Command Detailed

Source: Internet
Author: User
Tags file copy rsync


Installation
Yum Install rsync

Rsync has six different modes of operation.
rsync [OPTION] ... SRC DEST
rsync [OPTION] ... SRC [[Email protected]]host:dest
rsync [OPTION] ... [[email protected]] HOST:SRC DEST
rsync [OPTION] ... [[email protected]] HOST::SRC DEST
rsync [OPTION] ... SRC [[Email protected]]host::D EST
rsync [OPTION] ...
Rsync://[[email protected]]host[:P ort]/src [DEST]
Copy the local file. This mode of operation is initiated when both the SRC and DES path information do not contain a single colon ":" delimiter.
Rsync-a/data/backup
Use a remote shell program (such as rsh, SSH) to copy the contents of the local machine to the remote machine. This mode is started when the DST path address contains a single colon ":" delimiter.
Rsync-avz *.c FOO:SRC
Use a remote shell program (such as rsh, SSH) to copy the contents of the remote machine to the local machine. This mode is started when the SRC address path contains a single colon ":" delimiter.
Rsync-avz Foo:src/bar/data
Copy files from the remote rsync server to the local machine. This mode is started when the SRC path information contains the "::" delimiter.
Rsync-av [Email Protected]::www/databack
Copy files from the local machine to the remote rsync server. This mode is started when the DST path information contains the "::" delimiter.
rsync-av/databack [Email protected]::www
The list of files for the remote machine is listed. This is similar to the rsync transfer, but only if the local machine information is omitted from the command.
Rsync-v rsync://192.168.78.192/www

Parameter option description
-v,--verbose verbose mode output.
-q,--quiet thin output mode.
-c,--checksum turn on the check switch to force a checksum on the file transfer.
-a,--archive archive mode, which means that files are transferred recursively, and all file attributes are maintained, equal to-rlptgod.
-r,--recursive subdirectories are processed in recursive mode.
-r,--relative uses relative path information.
-b,--backup Create a backup, that is, for the purpose already exists with the same file name, the old file is renamed to ~filename. You can use the--suffix option to specify a different backup file prefix.
--backup-dir store backup files (such as ~filename) in the directory.
-suffix=suffix defines the backup file prefix.
-u,--update only updates, that is, skips all existing DST, and the file time is later than the file to be backed up and does not overwrite the updated file.
-l,--links keep the soft link knot.
-l,--copy-links treats soft links as if they were regular files.
--copy-unsafe-links only copies links to the SRC path directory tree.
--safe-links ignores links to links other than the SRC path directory tree.
-h,--hard-links preserves hard links.
-p,--perms maintain file permissions.
-o,--owner Keep the file owner information.
-g,--group maintain file group information.
-d,--devices Keep the device file information.
-t,--times Keep file time information.
-s,--sparse special processing of sparse files to save DST space.
-n,--dry-run reality which files are to be transmitted.
-w,--whole-file copy files without incremental detection.
-x,--one-file-system do not cross file system boundaries.
The block size used by the-b,--block-size=size test algorithm is 700 bytes by default.
-e,--rsh=command Specifies that data synchronization is done using rsh and SSH.
--RSYNC-PATH=PATH Specifies the path information for the rsync command located on the remote server.
-c,--cvs-exclude uses the same method as CVs to automatically ignore files, which are used to exclude files that you do not want to transfer.
--existing only updates those files that already exist in DST, without backing up those newly created files.
--delete Delete those files that are not in the DST SRC.
--delete-excluded also deletes those files that are excluded by the option specified by the Receive side.
After the--delete-after transmission is finished, delete again.
--ignore-errors timely IO errors are also deleted.
--max-delete=num delete up to NUM files.
--partial retains files that are not fully transmitted for any reason, in order to expedite subsequent transmissions.
--force forcibly deletes the directory, even if it is not empty.
--numeric-ids does not match the user and group ID of the number to the user name and group name.
--timeout=time IP time-out, in seconds.
-i,--ignore-times does not skip files that have the same time and length.
--size-only when deciding whether to back up a file, just look at the file size regardless of the file time.
--modify-window=num determines whether the file is time-stamped with the time Stamp window, which defaults to 0.
-T--temp-dir=dir creates a temporary file in Dir.
--compare-dest=dir also compares the files in DIR to determine if a backup is required.
-P is equivalent to--partial.
--progress shows the backup process.
-z,--compress the files that are backed up are compressed at the time of transmission.
--EXCLUDE=PATTERN Specifies to exclude file patterns that do not need to be transferred.
--INCLUDE=PATTERN Specifies the file mode that is not excluded and that needs to be transferred.
--exclude-from=file excludes files in the specified schema in file.
--include-from=file does not exclude files that specify pattern matching.
--version print version information.
--address is bound to a specific address.
--CONFIG=FILE specifies a different configuration file and does not use the default rsyncd.conf file.
--port=port specifies a different rsync service port.
The--blocking-io uses blocking IO on the remote shell.
-stats gives the transfer status of some files.
--LOG-FORMAT=FORMAT Specifies the log file format.
--password-file=file gets the password from file.
--bwlimit=kbps limits I/O bandwidth, Kbytes per second.
-H,--HELP Displays help information.


How to use
No Password Synchronization
Server-side modification configuration file/etc/rsyncd.conf
#This is the rsync daemon configuration

#global settings
PID file =/var/run/rsyncd.pid
Port = 873
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsync.log
GID = root
UID = root

#module settings
[Share_data]
Path =/web/rsync/share_data
Use chroot = no
Max connections = 15
Read Only = yes
Write only = no
List = no
Ignore errors = yes
Timeout = 120
/usr/bin/rsync--daemon
Mkdir-p/web/rsync/share_data
Client synchronization
Rsync-avz--progress [Email protected]::share_data/home/hadoop/share_data
Client Throttling traffic synchronization
Rsync-avz--bwlimit=50--progress [email protected]::share_data/home/hadoop/share_data


Have password synchronization
Server-side modification configuration file
#global settings
PID file =/var/run/rsyncd.pid
Port = 873
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsync.log
GID = root
UID = root

#module settings
[Auth_data]
Path =/web/rsync/auth_data
Use chroot = no
Max connections = 15
Read Only = yes
Write only = no
List = no
Ignore errors = yes
Timeout = 120
Auth users = Hadoop
Secrets file =/etc/rsyncd.passwd
echo "hadoop:password123" >/ETC/RSYNCD.PASSWD
chmod 600/etc/rsyncd.passwd
Mkdir-p/web/rsync/auth_data


Client synchronization
echo "password123" >/HOME/HADOOP/RSYNCD.PASSWD
chmod 600/home/hadoop/rsyncd.passwd
Rsync-avz--progress--password-file=/home/hadoop/rsyncd.passwd [email protected]::auth_data/home/hadoop/auth_data


Write synchronization
Server-side modification configuration file
#global settings
PID file =/var/run/rsyncd.pid
Port = 873
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsync.log
GID = root
UID = root

#module settings
[Write_data]
Path =/web/rsync/write_data
Use chroot = no
Max connections = 15
Read Only = no
List = no
Ignore errors = yes
Timeout = 120
Auth users = Hadoop
Secrets file =/etc/rsyncd.passwd
Mkdir-p/web/rsync/write_data


Client synchronization
echo "123" >/home/hadoop/write_file
Export rsync_password= "password123"
Rsync-avz--progress--delete/home/hadoop/write_file [email protected]::write_data


Limit IP or network segment
#global settings
PID file =/var/run/rsyncd.pid
Port = 873
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsync.log
GID = root
UID = root

#module settings
[Write_data]
Path =/web/rsync/write_data
Use chroot = no
Max connections = 15
Read Only = no
List = no
Ignore errors = yes
Timeout = 120
Auth users = Hadoop
Secrets file =/etc/rsyncd.passwd
Hosts allow = 192.168.2.32 192.168.1.0/24

Configuration Instructions
The PID file = <FILE> process writes the files.
Port = specified, default is 873.
Address = Specifies the server IP address.
UID = server-side transfer file, specify user execution, default nobody.
GID = server-side transfer of files, specified user group execution, default nobody.
Use chroot = Server daemon will be chroot to the file system directory, the benefit is to protect the system from the installation vulnerability attack. The disadvantage is that superuser privileges are required.
Read Only = Yes|no read-only selection, which does not allow the client to upload files to the server.
Write only = Yes|no Write selection.
Hosts allow = restricts IP or network segments, you can specify a single IP, or you can specify an entire network segment for increased security. The format is a space interval.
Max connections = Maximum number of client connections.
MOTD file = <FILE> is used to define server information, and when a user logs in, they see the content information in the file.
Log file = <FILE> logs for the server.
Transfer logging = Yes|no whether to print the transfer log
Log format = log formats (%t%a%m%f%b)
Lock file = <FILE> lock files.
Path = <DIR> Specifies the location of the synchronization file directory.
Auth users = Authenticated Users, must exist on the server.
List = Yes|no whether the directory on the Rsync server that provides synchronization data is displayed on the server module. The default is yes.
Ignore errors ignores IO errors.
Secrets file = <FILE> password to store files, password login is used.
Comment = annotations can be customized.
Exclude = exclude directories or files, spaces can be separated between directories.
Rsync has three configuration file rsyncd.conf (Master profile), rsyncd.passwd (password file), RSYNCD.MOTD (RYSNC server information).
The file attribute of the rsyncd.passwd password file is set to root, and the permission is set to 600, otherwise it cannot be successfully backed up.
For security purposes, the properties of a file must be only master readable.
The password file format is:
User name: Password

rsync Command Detailed

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.