Computer Backup With Rsync

I like to use simple scripts to do my backups. That way I know what is going on and I know it is working. That is why I backup with Rsync on Linux and use Robocopy for my backups on Windows.

Backup With Rsync

I have always been a little obsessive when it comes to backups but I have never lost data I could not get back. So I guess that means I am lucky or I am doing something right.

Organize Your Files To Make Backups Simpler

The first step is to make sure your files are well organized and not scattered all over your computer. Otherwise, it is easy to miss things and you end up not having them backed up.

For example, I try to save everything in my documents folder other than pictures and music. This way I can just back up the documents folder and know I have almost everything.

Ones your files are organized into just a few locations then you only have a few places to backup. It makes things much easier to work with.

My Rsync Backup Routine

I have a simple backup script on my desktop. When used it mounts my network share and starts up Rsync. Then it copies everything from my Desktop, Documents, Music, and Pictures to the network location. I even add game save locations of the current game I am playing if it is not already in the documents folder.

I have a script like this on all my computers copying to their own folder on the network share.

Then I have another script that rsync copys the whole backup share to a 2TB hard drive I have. In fact, I have a few big hard drives laying around so I kind of rotate them. This way if my network server dies I still have everything backed up. To make it easier I use a hard drive dock.

Then the last step to my Rsync backup routine is to have a copy of the files off-site. Such as in a cloud backup or just storing a extra backup drive at another location. Then if something awful were to happen and your house burnt down you would not lose all your files.

My Rsync Options

Rsync Options

It’s not hard to backup with Rsync. For me, the hardest part was learning what flags and options I needed to use.

The “-a” option stands for archive. It tells Rsync to copy the directories recursively, backup symlinks, keep the same permissions and groups on files, and keep the same modification times on copied files.

For verbose mode I set “-v” because I like to see the details of what is going on.

–delete” is the same as /MIR in Robocopy. It makes sure the destination matches the source by deleting any extra files the destination has.

–progress” is another flag that shows more info about what is going on.

My Backup Script

Here is the script on my desktop to backup to my network share. Lines that start with # are just comments and not part of the code.

#!/bin/bash
# rsync script

sudo mount -t cifs -o username=zack //10.0.0.5/nas /mnt/NAS/

sudo rsync -av --delete --progress '/home/zack/Desktop/' '/mnt/NAS/Backups/Zack/Computer Backup/Desktop/'

sudo rsync -av --delete --progress '/home/zack/Documents/' '/mnt/NAS/Backups/Zack/Computer Backup/Documents/'

sudo rsync -av --delete --progress '/home/zack/Pictures/' '/mnt/NAS/Backups/Zack/Computer Backup/Pictures/'

sudo rsync -av --delete --progress '/home/zack/Music/' '/mnt/NAS/Backups/Zack/Computer Backup/Music/'

sudo umount /mnt/NAS/

This script is saved as a .sh file like “BackupToNas.sh”. To run it you have to type something like this in the Terminal.

sudo su BackupToNas.sh

And to backup my NAS to a backup drive I made another script.

#!/bin/bash

sudo mount -t cifs -o username=zack //10.0.0.5/nas /mnt/NAS/

sudo rsync -av --delete --progress '/mnt/NAS/' '/run/media/zack/Backup/NAS Backup/'

#saves last backup date to text file.
sudo date &> '/run/media/zack/Backup/LastBackup.txt'

sudo umount /mnt/NAS/

Cloud Backup

And as always I would also suggest adding a cloud backup to your setup. Or store backup drives in another location. That way if the worst happens and you lose your home at least you will still have those family pictures and important files somewhere safe.

I personally use IDrive running on my NAS for cloud backups. if you’re interested in checking that out I wrote some about it.

What do you do for backups?

Rsync and using Linux full time are still kind of new to me so the process could probably be improved. Do you have any tips or suggestions? I would love to hear them in the comments below.


Join The Community

I hope you enjoyed this article! I am always posting new and helpful things! If you like what you see then I'd love to be able to send you more! Please subscribe to my newsletter for the latest information and exclusive content!

Would you kindly share this post?

Leave a Reply

Your email address will not be published. Required fields are marked *