We always encourage our clients and any user out there to make sure they have backups, and if they can have backups of their backups even better!
One of the handiest tools you’ll ever have on Linux (and other *nix systems) is rsync. As the name implies, rsync is used to sync files on remote and local machines. You can use rsync to copy files to remote systems and back again, or to make backups to locally mounted hard drives. I really like rsync as it's very simple to use but you can do pretty advanced stuff with it.
In this guide we'll go over the process of using rsync to backup large files on linux systems.
The simple command for rsynsc the following:
rsync -av SRC DST
Where SRC is the source where the actual file are, if ran locally it can be the local path (i.e: /home/owned/mydocuments) and DST would be the destination folder, which can be either a local folder, can even be a mounted external hard drive (i.e: /mnt/my-usb-drive. So with this explanation a command can look like this:
rsync -av /home/owned/mydocuments /mnt/my-usb-drive
This should basically copy all files and folder currently in /home/owned/mydocuments over to /mnt/my-usb-drive, if the folder already exists on the destination then it will only copy over changed files, so it you run this say on a daily basis, it shouldn't take a long as it would typically take the first time you run it.
If you want to see the actual progress you can add the --progress option, should look like this:
rsync -av --progress /home/owned/mydocuments /mnt/my-usb-drive
If you want rsync to delete the files on destination that are no longer on the source you can add the --delete option and the command would look like this:
rsync -av --progress --delete /home/owned/mydocuments /mnt/my-usb-drive
If you want rsync to exclude certain folders that contain files that you do not wish to backup you can use the --exclude-from option like so:
rsync -av --progress --delete --exclude-from '/home/owned/mydocuments/music' /home/owned/mydocuments /mnt/my-usb-drive
Now, this is all nice, however, we're still just backing up locally while the ideal is always to backup remotely, even better if it's to a destination under a different roof, so we'll see how to backup over ssh using all the previously mentioned options:
rsync -av --progress --delete --exclude-from '/home/owned/mydocuments/music' /home/owned/mydocuments [email protected]:/backups
Where 10.0.0.2 is the IP of the destination server and /backups is the folder where backups are stored
What if the remote server has a different ssh port than the standard? no problem, we can add --rsh='ssh -p4444' in the command line which servers to specify 4444 as the remote ssh port:
rsync -av --progress --rsh='ssh -p4444' --delete --exclude-from '/home/owned/mydocuments/music' /home/owned/mydocuments [email protected]:/backups
Now, say you want to do it the opposite way, you want to rsync files from a remote location over ssh, it's as simple as moving the DST and SRC arguments the other way around:
rsync -av --progress --rsh='ssh -p4444' [email protected]:/backups /home/owned/mydocuments
You should be careful with the --delete command as if not used properly you can make a mess; a good thing is that you can use the -n option if you're unsure, this way it will display the expected result of the rsync command without making any changes.
Now that you're familiar with the rsync command or need a little more practice you can you should check out our Cloud VPS plans here: https://owned-networks.net/kvm.html
You can use our Cloud VPS to either practice or as a remote storage or your backups :)