Backup Linux Data With Rsync Over SSH
2 min read

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:

  • -a: Recursive. Recurse into directories and preserve most information.
  • -v: Verbose. See what you are backing up.
  • --delete: Delete all files in directory2 that does not exist in directory1.

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/