Apr 262012
 
Article Server Administration

(Leer este artículo en español)

The main purpose of the rsync command in Linux distributions is to copy contents from an origin to a destination, but it can also be used to state the differences between to directory trees. Besides, both origin and destination can be local, or reside in a remote server.

We comprare directoryA and directoryB using two rsync commands:

The basic usage of the rsync command to copy directoryA to directoryB is:

Warning: It is important to end the origin directory name with the ‘/’  character, because otherwise the rsync would create a subdirectory named ‘directoryA’ under the destination directory ‘directoryB’.

The options “–dry-run -v” tell rsync not to perform any actual copy, but just to print the names of the files that it would copy.

Option “-r” tells rsync to execute recursively.

Option “-c” sets that the file comparison is to be performed by computing a checksum of the content of the files, instead of just comparing the date and size of the files.

Finally, option “–delete” tells rsync to remove existing files in the destination directory, that do not exist in the origin directory (but because of  the –dry-run option, it will just print the names of the files that it would delete, with lines like this: “deleting filename“).

The first of the above rsync commands will print:

    • The names of files existing in both directories, having different content.
    • The names of files existing only on directoryB and not in directoryA (as files to be deleted)

The second command will print:

    • The names of files existing in both directories, having different content (these should be the same as those printed by the first command)
    • The names of files existing only on directoryA and not in directoryB (as files to be deleted)

Example:

By comparing to mediawiki installations wikiA and wikiB, we get the the output:

As we see, in this case LocalSettings.php files exist in both directories, but their content differs, and there are also some images existing only under wikiA, and some images existing only under wikiB.

 

 Posted by at 5:06 pm

 Leave a Reply

(required)

(required)