I recently discovered a tool which turned out to be useful for backing up my local folders, namely: rsync. It’s a straightforward command-line utility that makes it really easy to maintain a mirror of local data on any distant support. Basic usage for this purpose is:
$ rsync -auvz --delete ./local-folder/ /mnt/remote-folder/
-astands for "archive" mode (preserve permissions, dates, etc.),
-ustands for "update" only, i.e. don’t re-send or overwrite newer files,
-vstands for "verbose", so we can see a list of files being processed,
-zenables file compression for faster transfers,
--deletemeans we delete files that don’t exist any more in the local folder.
The verbose mode enabled by
-v is not necessary depending on your use case. These other parameters can also come in handy:
--excludecan be used to specify files or filename patterns to ignore,
--progressdisplays a progression bar, e.g. to check that a big file transfer is not hanging.
man rsync for more details and options.
The only thing to be careful about with
rsync is the addition, or not, of a trailing slash. If there is no trailing slash, the corresponding object is treated as a target, while if there is a trailing slash, the corresponding object is treated as a directory containing the target files. It's clearer with an example: suppose we have a directory
foo containing the file
README, and we want to sync it to a directory
bar. If we do:
$ rsync -auvz ./foo ./bar/
foo will be copied to the target location
bar/, and we will end up with the following file tree:
./foo ./foo/README ./bar/ ./bar/foo ./bar/foo/README
On the contrary, if we do:
$ rsync -auvz ./foo/ ./bar/
Then the content of
foo is synced with the content of
bar, and we get:
./foo ./foo/README ./bar/ ./bar/README
So, make sure that the source and destination folders are consistent trailing-slash-wise.
There are no comments yet. Feel free to leave a reply using the form below.