Using rsync to backup a remote folder onto your computer via SSH
I've been having a hard time remembering the correct way of doing this, so I figured I write it down…
Backup the "folder":
# rsync -avz -e ssh user@remotemachine:/some/folder/ /backup/some/folder/
When using a different ssh port (xxxx is the ssh port number):
# rsync -avz -e ‘ssh -p xxxx' user@remotemachine:/some/folder/ /backup/some/folder/
When there is a space in the folder name, you need to put single or double quotes around the folder name:
# rsync -avz -e ssh user@remotemachine:/some/folder/'with a lot of spaces'/ /backup/some/folder/'with a lot of spaces'/
Some cool commands you can add:
--delete
will remove files from the destination folder that are not present in the origin
--progress
shows a nice % progress on the current file
# rsync -avz -e --delete --progress ssh user@remotemachine:/some/folder/'with a lot of spaces'/ /backup/some/folder/'with a lot of spaces'/
This will download the content of the remote folder with a lot of spaces to your local machine with a folder of the same name, while deleting any file that is inside your local folder and not in the remote folder, and it will give you some details to the files being downloaded.
1885