Skip to content

Latest commit

 

History

History
111 lines (79 loc) · 6.51 KB

rsync.wiki

File metadata and controls

111 lines (79 loc) · 6.51 KB

Simplest example

rsync -avz src zhangliyong@10.131.243.61:./data

INCLUDE/EXCLUDE PATTERN RULES

You can include and exclude files by specifying patterns using the "+", "-", etc. filter rules (as introduced in the FILTER RULES section above). The include/exclude rules each specify a pattern that is matched against the names of the files that are going to be transferred. These patterns can take several forms:

  • if the pattern starts with a / then it is anchored to a particular spot in the hierarchy of files, otherwise it is matched against the end of the pathname. This is similar to a leading ^ in regular expressions. Thus "/foo" would match a name of "foo" at either the "root of the transfer" (for a global rule) or in the merge-file's directory (for a per-directory rule). An unqualified "foo" would match a name of "foo" anywhere in the tree because the algorithm is applied recursively from the top down; it behaves as if each path component gets a turn at being the end of the filename. Even the unanchored "sub/foo" would match at any point in the hierarchy where a "foo" was found within a directory named "sub". See the section on ANCHORING INCLUDE/EXCLUDE PATTERNS for a full discussion of how to specify a pattern that matches at the root of the transfer.
  • if the pattern ends with a / then it will only match a directory, not a regular file, symlink, or device.
  • rsync chooses between doing a simple string match and wildcard matching by checking if the pattern contains one of these three wildcard characters: '*', '?', and '['].
  • a '*' matches any path component, but it stops at slashes.
  • use '**' to match anything, including slashes.
  • a '?' matches any character except a slash (/).
  • a '[']introduces a character class, such as [a-z] or :alpha:.
  • in a wildcard pattern, a backslash can be used to escape a wildcard character, but it is matched literally when no wildcards are present.
  • if the pattern contains a / (not counting a trailing /) or a "**", then it is matched against the full pathname, including any leading directories. If the pattern doesn't contain a / or a "**", then it is matched only against the final component of the filename. (Remember that the algorithm is applied recursively so "full filename" can actually be any portion of a path from the starting directory on down.)
  • a trailing "dir_name/***" will match both the directory (as if "dir_name/" had been specified) and everything in the directory (as if "dir_name/**" had been specified). This behavior was added in version 2.6.7.
  • For example:*
rsync --verbose --progress --stats --compress --rsh=/usr/local/bin/ssh \


use rsync as daemon

reference : http://everythinglinux.org/rsync/

On the server machine you need to set up a daemon to run in the background and host the rsync services. First – before you start the daemon – you need to create an rsync daemon configuration file. To do this in Ubuntu, create a file named rsyncd.conf in the /etc directory, i.e.

you@your-computer:~$ sudo gvim /etc/rsyncd.conf

Now enter the following information into the rsyncd.conf file: motd file = /etc/rsyncd.motd log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock

[simple_path_name]

   path = /rsync_files_here
   comment = My Very Own Rsync Server
   uid = username  #default "nobody"
   gid = username  #default "nobody"
   read only = false
   list = yes
   auth users = user #this can not exist on the server
   secrets file = /etc/rsyncd.scrt

change username, the username will be the ower of the files transfered, it should exist on the server. path - this is the actual filesystem path to where the files are rsync'ed from and/or to. comment - a short, descriptive explanation of what and where the path points to for listings. auth users - you really should put this in to restrict access to only a pre-defined user that you specify in the following secrets file - does not have to be a valid system user. secrets file - the file containing plaintext key/value pairs of usernames and passwords. for example: auth users = lab, test the value of /etc/rsyncd.scrt is: lab:lab test:test abc:abc

Now you should have all the configuration information necessary, all that’s left to do is open the rsync port and start the daemon.

To open the port, open the /etc/default/rsync file, i.e.,

you@your-computer:~$ sudo gedit /etc/default/rsync

and set RSYNC_ENABLE=true.

Now to start the daemon,

you@your-computer:~$ sudo /etc/init.d/rsync restart

There you have it, your rsync server should be up and running!

Now you probably want to know how to copy files from your remote machine to your server. $ rsync -vr SRC username@ip-address::workspace/DEST

The -vr flags are for verbose output and recursive (so entire directory structures can be copied). The SRC is the root directory of your source files. If you wanted to sync your entire Eclipse workspace with the workspace on your server, this would be the workspace directory; the recursive flag would then go through all the projects within your workspace directory and copy everything. The username should match the username in the /etc/rsyncd.conf file. The “workspace” after “::” should match your path name in the /etc/rsyncd.conf file, i.e., the “[workspace]“. DEST is then appended to the path from the /etc/rsyncd.conf file, i.e., /home/username/workspace/DEST.

When you enter this command you should see the contents of the /etc/rsyncd.motd file appear and you should be prompted for the password corresponding to the username provided. This username/password pair should match the contents of the /etc/rsyncd.scrt file. Once you enter the password correctly, the sync will begin!

Here’s an example with the username on the server “nick” and the server ip-address is “192.168.0.8″: /etc/rsyncd.conf:

motd file = /etc/rsyncd.motd

[workspace] path = /home/nick/workspace comment = My Eclipse workspace directory. uid = nick gid = nick read only = false auth users = nick secrets file = /etc/rsyncd.scrt

/etc/rsyncd.motd:

Welcome to my rsync server!

/etc/rsyncd.scrt:

nick:mybirthday

  • _Important_*: You must make /etc/rsyncd.scrt not accessible to other users. it should be: -rw-------
To sync the “Java2D” projects in the workspaces of the server and client machines (entered in Cygwin on client/remote machine):

$ rsync -vr /Documents and Settings/Nick/workspace/Java2D/ nick@192.168.0.8::workspace/Java2D Welcome to my rsync server!

Password: mybirthday