Detailed instructions on installing and using Rsync commands

Source: Internet
Author: User
Tags file transfer protocol man rsync

Rsync makes it easier and faster to synchronize two machines, such as Laptops and Desktops. This provides an efficient algorithm and multiple options. In addition, if you do not like the command line operation, you can use several graphical tools to make rsync easier.
If you are using both a laptop and a desktop computer, you may need to synchronize them in a timely manner. In addition, in addition to running synchronization at home, you may also want to run synchronization from a remote site. For me, I use a laptop during the trip, during this period, you want to ensure that the work on your laptop is backed up on your desktop. Losing your laptop and losing all your work is a real disaster !) There are many solutions to this problem: This article describes a tool-rsync-and several related tools, which provide a simple synchronization process.

What is the Rsync command?

What is the rsync application in Linux? And UNIX? Widely used file transfer and synchronization programs, and it has been transplanted to Windows? . Its key feature is a very fast algorithm that sends file differences only through data links, so the total amount of data transmitted between machines is minimized. If you use a File Transfer Protocol [FTP] or a utility such as rcp and scp, a complete File will be sent even if only one byte is modified ). Of course, rsync cannot only process existing files: it can also process files and directories that only exist at one end of the link. Finally, we can use this tool through non-broadband connections to optimize communication by compressing data.

Rsync status

Rsync utility was initially developed by Samba developer Andrew Tridgell. The software uses GNU General Public License (GPL). Its current version is 3.0.5 released in December 2008.
 
Obtain and install rsync

You can find the Binary Package pre-compiled for most of the current Linux releases. First, you should find the package that suits you. I use Smart to manage OpenSUSE packages, so I only need to use the sudo smart install rsync command to install the latest version of rsync. If you prefer to compile it yourself, you can obtain the source code by referring to the link in the reference material) and use the traditional configure, make, make install method to install it. For detailed steps, see the README file in the source code.

To ensure Secure communication, install Secure Shell (ssh ). You can use remote shell [rsh], but it is not safe enough ). OpenSSH is a free implementation of ssh, available in all releases. You also need to open a port on the firewall to allow computers to connect to each other. These are all standard configurations. For more information, see the links in references.

Run the Rsync command as a daemon

There are two methods to run rsync: run as a daemon and as needed. If you only want to synchronize the two computers, there is no obvious difference in which method to use. Run rsync as a daemon. Use the rsync -- daemon command. This command is applicable to servers. Multiple users can synchronize their computers to the servers. You can use man rsyncd. conf to understand the options that can be specified. However, you do not need to use complex configurations to synchronize Laptops and Desktops.

Use the Rsync command

Now, we use rsync to directly synchronize the laptop to a remote server. To do this, you can use code similar to listing 1. You can also synchronize the remote server to the notebook file to send the slave server to the notebook), or synchronize two local directories, but cannot synchronize the two remote servers.

Listing 1. Two versions with the same rsync command


rsync --compress --recursive --delete --links \--times --perms --owner --group \--verbose --progress --stats \--rsh="ssh" \--exclude "*bak" --exclude "*~" \/my/path/at/the/laptop/* myserver:/some/path/at/the/serverrsync -zrltpogve "ssh" --progress --stats --delete \--exclude "*bak" --exclude "*~" \/my/path/at/the/laptop/* myserver:/some/path/at/the/server

Note that the order of options in Listing 1 is arbitrary, and most options have short formats. First, -- compress or-z) specifies to compress data, which can save bandwidth. Always use this option. On a very high-speed data link, compression is not required. However, compression is helpful for most remote connections ). You can use the supplementary option -- compress-level = level to specify the compression level. However, standard compression levels are acceptable.

The -- recursive (-r) option enables rsync to recursively copy all directories. This copies all the files in the directory, including the subdirectories and their contents. If you do not need this function, you can use the -- dirs option (-d) to produce the opposite effect: Skip the subdirectory and its content.

By default, rsync copies the required files to the target computer, but does not delete the additional files. By using the -- delete option, the target directory will be exactly the same as the original directory. Note: If you synchronize an empty directory to a remote directory, all contents in the remote directory will be deleted!

If the original directory contains symbolic links, the -- links option or-l will re-create these symbolic links in the target directory. Another method is to use -- copy-links or-L) to copy the file or directory pointed to by the symbolic link, rather than copying the symbolic link itself. If a signed link points to a file or directory outside the copied tree, This is a security risk.) You can use -- copy-unsafe-links. -- Safe-links option ignores such links, which is safer.

The following four options are -- times, -- perms, -- owner, and -- group, and-tpog, respectively. rsync maintains the original update timestamp, permission, owner, and group information. You can use -- archive or-a to specify all these options at the same time. This also sets the -- recursive and -- links options.

The following three options: verbose, -- progress, and -- stats provide a large amount of information about the operations being performed by rsync. If you are not interested in the information, you only need to skip it. Unless an error occurs, rsync will run quietly.

Although the current rsync version uses ssh by default, you can use the -- rsh or-e) option to force ssh. You can add additional ssh parameters, such as -- rsh "ssh-p 12345", to allow ssh to use non-standard ports ".

You can use the -- exclude option and the corresponding -- include) to select the file to be synchronized. In this example, common backup files are excluded. Files should be excluded and included as needed to optimize the sent content.

Finally, specify the source and target paths. Do not forget the last/*. Otherwise, the result may not meet your expectations. You can see the differences between some/path, some/path/, and some/path/* in the document. However, using/* is the safest method.

You can use the-a option (-- archive) to simplify the command in Listing 1, as shown in Listing 2. If you run rsync on the server as the root, option-a may copy some additional content-please refer to the documentation-this is not a safe practice ). Rsync also has many options. You can use rsync -- help and man rsync to understand all options.

To view the full text, click: rsync command family

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.