rsync: copy files the intelligent way

You probably heard about last Friday's massive cyber attack that affected millions of outdated machines that still run Windows XP, but also newer version. Luckily the pandemic got halted almost by sheer luck (read more at hackaday).

Anyway, it could have affected any of us (maybe dual-boot?), which alerted me of the fact that I had not backed up my files for quite some time now. This gave me two options. Either plug in my external backup HDD and copy everything with my file browser (overwriting old files), or do it the intelligent way: an incremental update to my backup with rsync to only copy modified files.

rsync is an open source utility that provides fast incremental file transfer. its main advantage over simply copying files with a file browser is that is is capable of skipping files that are already present at the destination (i.e. continue an interrupted copy process) and deleting files at the source which are not present at the source (i.e. updating an old system backup). Making it a great choice to copy large and highly nested folder structures to a remote system without fear of connection loss, or easily keep an updated system backup.

How to use rsync 

$ rsync [options] [origin] [destiny]

Interesting options are:

-a, --archive: archive mode; equals -rlptgoD.
-r, --recursive: recurse into directories.
-l, --links: copy symlinks as symlinks.
-p, --perms: preserve permissions.
-t, --times: preserve modification times.
-g, --group: preserve group.
-o, --owner: preserve owner (super-user only).
-D, --devices: preserve device files.

--delete: delete extraneous files from dest dirs. Useful to update an existing update.

-z, --compress
: compress file data during the transfer. Use only if your connection is more constricted that you CPU power on both sides.

-h, --human-readable
: output numbers in a human-readable format.

-P, --progress
: show progress during transfer.

-b, --backup
: preexisting destination files are renamed as each file is transferred or deleted. Useful to keep a detailed backup over time, but keep in mind that it grows over time.

-v, --verbose
: increase verbosity and provide a summary after syncing.

My prefered way of using rsync is with the options -avhP, which comes very handy to manage large backups while visualizing what is being copied.

Remote rsync-ing

Copying to a remote server is as easy as the following example. Suppose we have a local folder `/home/andy/photos/` and a remote folder `/home/backups/` at a server located in our LAN at (where my user name is andy). If you want to copy your photos over, simply:

$ rsync -avhP /home/andy/photos andy@

No comments :

Post a Comment