Don’t forget to –delete when rsyncing

The program rsync is available on most *NIX/Linux platforms, but – contrary to the implication by its name – the program synchronizes only when used with the --delete-option.

Let’s clarify first, what I mean by synchronizing: Assume we have a directory called fooboz, said directory contains two files, one named fooboz1.txt and another called fooboz2.txt. We want to create a mirror of the directory in fooboz_bu and use the following command:

rsync -vaR /fooboz/ /fooboz_bu/

After the successful completion of the command, the directory fooboz_bu contains the directory fooboz with the two files fooboz1.txt and fooboz2.txt. You might have guessed it, the -vaR-option means: be verbose (v), run in archive-mode (a), and do it recursively (R). Archive-mode means, that pretty much everything is a perfect mirror of the source.

If I modify a file in fooboz, it will be copied during the next invocation of the rsync-command shown above. What if I delete one of the files? Right, nothing. The file will be missing in the source-directory, but will prevail in the backup-directory unless we add the --delete-option to the command, that is:

rsync -vaR --delete /fooboz/ /fooboz_bu/

Now the two directories will be in sync, means, after the latter command completes, both directories will look the same.

Disclaimer: Do a test-run on data you could afford to loose, seriously. If you should get something wrong with this command, you might destroy the very data you wanted to backup.

Technorati Tags: ,