Rsync is a file syncing command line utility that can sync across many computers, including servers. It can copy incremental files and resume a sync if it was abruptly cut short. You can even use it to update your website by editing your website locally and running an rsync command to send the files to the server.

Rsync should come installed with most Linux systems if not just install it with your package manager sudo apt install rsync.

The only commands you’ll need

Rsync is easy to understand, it works as a copy command locally: rsync file file2. But the power of rsync is copying over to other machines. Let’s try it.

1rsync file user@IP 

That copies over file to whatever user you specified. It puts it in the users home directory. To specify directory:

1rsync file user@IP:/home/user/test

That would put the file in the test dir.

You can get verbose messages:

1rsync -v file user@IP.

Rsync works with domain names:

1rsync file root@mydomain.com

Transfer directories:

1rsync -vr testdir user@IP.

The coolest feature is rsync will only sync the changes made to a file, if you’re copying entire directories but only change one file, rsync will only copy over the edited file.

You can do it like so:

1rsync -urv testdir user@IP 

All you need is the -u flag which means update.

If you want to create archives and preserve permissions:

1rsync -av testdir user@IP

And now the command to update your website locally:

1rsync -urvP --delte-after ~/.local/src/site/ root@mydomain.com:/var/www/mysite/

That updates your site every time you make a change to a file. The -P command means partial so if the connection drops it’ll resume where it left off. The --delte-after command deletes any duplicate files and keeps your live site’s files the same as your local copy.

That’s it, a quick tutorial on rsync.