Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Rsync is a data transfer tool. To use rsync you will be provide it with a source, and a destination. For each file in the source, rsync will first look to see if the file exists in the target. If not, then rsync will transfer a copy of the file to the target. If file does exist on the target, then rsync confirms that the files are the same. If not, then it determines the smallest amount of data that needs to be transferred to make the target file look like the source file. This makes rsync ideal for mirroring sets of files. Because rsync ignores files that are up to date it's also useful for resuming a transfer that might have gotten interrupted. However, this powerful piece of software can easily be used to create a mess, or damage files. If you wish to use rsync you should carefully read through this document to make sure you understand its proper use. It does also require a bit more familiarity with how files are stored, and accessed in UNIX. If you are still not comfortable with this, you should visit our New Users Guide which has some references for learning to work with UNIX. You might also refer to our UNIXary which defines some commonly used terms.

UNIX users (and Mac by use of Terminal.app) can use rsync by typing

rsync opts  src tgt

src and tgt are the locations that you want to keep synced. The rule is that tgt will be made to look like src. There are several options. First, you can just use short names. For example,

rsync a b

will sync object a to object b where both a and b are in your current working directory. By object, it is meant either a file or a directory. For example,

rsync a b

will sync a to b. If a, and b are both files, then b is updated to look like a. If b is a directory, then b/a is updated to look like a. Keep in mind that "update" means "created" if it doesn't exist. If a is a directory, then rsync will fail because, by default, rsync will not transfer directories. You can get around this by using the -a option. In other words,

rsync -a a b

will transfer the directory a to become b. Typically, you will almost always be using -a, since it sets a number of other options which are used to help rsync mirror sets of files between two locations. With this use of rsync b/a is created or updated. If you use a/ as a source, then the contents of a are placed in b. You can also use the trailing slash with a target. For example, if a is a file, and you run

rsync -a a b

then either b (if it is a file), or b/a (if it is a directory) is updated. In the case that you want to guard against typos overwriting a file, you can use b/. Then if what you type is not a directory, rsync will refuse to transfer the file. To sum up

object meaning
a b sync object (file or directory) a to (file or directory b)
a/ b sync contents of directory a to b
a b/ sync a to directory b
a/ b/ sync directory a/ to b/

Until now we've just assumed that we are syncing files in the same directory. However, rsync will also sync files between directories. For example, if you have modified files in your home directory, you might want to make sure the changed files are in your personal directory in your lab folder. In this case you could run,

rsync -a a /share/FooLab/bar1234/ProjectFiles

which creates or updates /share/FooLab/bar1234/ProjectFiles/a. You can reverse this off course. Finally, rsync allows either the source or the target

src could be either a file, or a directory. If it is a file, then the file is simply synced over to the target. If, src is a directory, then it is still synced over in the obvious way and tgt/src is created. Note that in this case, all of the files that are contained in src, or in its sub directories are copied over (ie, the entire file tree rooted at src is copied over). This makes sense if you think that it has synced src, and it just happens that this case. You can also use src/ in which the files, or directories inside of src (the contents) are synced over into target. Here are some examples,

tgt can be another local directory, or it can be prefixed with a hostname to indicate that you wish to transfer the files to that system. If you just use a hostname, then it's assumed that you are specifying that the files should be synced in to your home directory. Here are some examples,

target meaning
b rsync to file or directory named b
b/ rsync specifically to a directory named b (ie, fail if it is not one)
/a/b/c rsync to a directory located by a full path name
host:a/b/c rsync to remote host, and store files in the path a/b/c relative to the user's home directory
host:/a/b/c rsync to remote host, and store files in the absolute path /a/b/c

CCBB UNIX users note: Please do not sync files

  • No labels