Backup Linux Data With Rsync Over SSH

How you can backup your data with Rsync in a Linux environment.


Rsync

Rsync can be used for backups, internal and external. The basic usage looks like this.

rsync /directory1 /directory2

This will backup your files in directory1 to directory2.

Some basics flags that can be good to use:

Rsync over SSH

If you want to backup your data to an external source, you can use SSH.

rsync  ~/directory1 root@<ip>:/directory2

This works the same way as above. You can also import your data by “reversing” the syntax.

rsync root@<ip>:/directory2  ~/directory1

Rsync over SSH with password

More often than not, you need to write a password to allow the backup to happen. In that case, you can use sshpass.

sudo apt-get install sshpass

The new syntax should look something like this.

sshpass -p 'sshpassword' rsync ~/directory1/ root@<ip>:/directory2/