What’s worse than breaking your system and not having a recent backup, or worse, no backup at all? A few things I’m sure, but it’s a pain, and can cost you time and money.

I’ll show you a very simple way to make daily backups using rsync and cron.

I will assume you already have a backup drive permanently mounted to your system. If not, here’s a quick guide on how to do that.

I decided to keep weekly backups, so the first step is creating a directory in your backups drive for each day of the week:

$ cd /path/to/backup/drive/

$ mkdir 1 2 3 4 5 6 7


Now we want to write a short shell script which backs up your system to the right directory based on the day of the week: backup.sh

#!/bin/bash

dow=$(date +%u) # day of week

sudo rsync -aAXv --delete / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found", "/swapfile"} "/path/to/backup/drive/$dow/"

Save this to where you keep your shell scripts.

We want to run this script daily. I run mine at 5am.

To do this, we want to edit our crontab. Since rsync needs superuser privileges, and we dont want to store our password as plain text in our user crontab, we’ll want to edit the root crontab.

$ sudo crontab -e


This will bring up our root crontab file for editing.


The syntax for a cronjob schedule is the following: 4 node beowulf cluster

So the entry for this job, running daily at 5:00 am, is:
0 5 * * * /path/to/shellscripts/backup.sh


That’s it. Cron will automatically reload any changed crontabs after editing. You’ll probably want to run your rsync command first and then try restoring from that backup using a liveUSB to make sure your backup actually works as such. An untested backup isn’t really a backup.