Thursday, July 7, 2022

Secure remote backups with Rsync and SSH

Many Linux users know rsync as a file transfer utility. Rsync is an efficient tool for automating remote backups of Linux, Windows, and even Mac OS X systems.

Prerequisites:
To perform secure remote backups, rsync and SSH must be installed installed on both local and target remote machine. Rsync can use SSH as a secure transport agent.
Make sure rsync is installed by opening a terminal session and typing rsync --version on each machine. You should see a message like rsync version 2.X.X protocol version X.
To ensure that sshd is running on a remote machine, enter a terminal session and type ssh <user>@<remote IP address>.

When all the prerequisites are met, select the folder that needs to be sync from local to the remote host and create a folder in the destination to store the backed up data.

rsync -avz -e ssh /some/small/directory/ remote_user@remotehost.com:/backup/destination/directory/

Please note that the trailing slash in the source directory causes rsync to copy only the contents of the source directory. Omitting the trailing slash causes rsync to copy both the directory name and its contents to the destination.