Backup Linux Data With Rsync Over SSH
How you can backup your data with Rsync in a Linux environment.
Rsync can be used for backups, internal and external. The basic usage looks like this.
rsync /directory1 /directory2
This will backup your files in
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
directory2that does not exist in
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
sudo apt-get install sshpass
The new syntax should look something like this.
sshpass -p 'sshpassword' rsync ~/directory1/ root@<ip>:/directory2/