Simple system backup using rsync

Preface

So now you’ve installed ALARM on your Pogoplug E02, who also delivers IP addresses in your local network with dnsmasq, set up Samba file sharing, when watching media using the Serviio DLNA server, while time is up to date. Everything works fine and dandy.

Of course you want to back it all up, so if the USB flash drive the system resides on dies, you can easily restore whole system on a new flash drive.


Backup

We will use a tool called rsync1, which is very good at keeping files at two computer systems the same. This way we can use the external media drive for backup.

We’ll create two files in your user /home directory. One is the script for backup, the other an inclusion/exclusion list.

$ touch ~/usbbackup.sh && backup.lst

Now we edit the backup.lst content. Here’s a good list to start.

# Include
+ /dev/console
+ /dev/initctl
+ /dev/null
+ /dev/zero

# Exclude
- /dev/*
- /run/*
- /proc/*
- /sys/*
- /tmp/*
- lost+found/
- /media/*
- /mnt/*

As an example destination, we will create a directory usbbackup on our external drive which is mounted at /media/hdd1 and accessible with Samba.

$ mkdir /media/hdd1/usbbackup

At the end, we edit the usbbackup.sh file.

#!/bin/bash
rsync -aAXHv --delete-excluded --exclude-from=backup.lst / /media/hdd1/usbbackup

We make the script executable and do the initial backup. We run with sudo to make sure everything gets copied.

$ chmod u+x usbbackup.sh
$ sudo ./usbbackup.sh

Now each time we will run the script, the rsync tool will copy the missing/changed files and keep both destinations / and /media/hdd1/usbbackup as exact two same copies, while only excluding files with - prefix from the backup.lst.


Restore

No backup is useful when you can’t easily restore it. If you ever find out your system has become unbootable, move the external hard drive (or perhaps copy the files regulary) on another system to restore the system on another flash drive. You’ll need a Linux system or a Virtual machine2 for that.

Repartition the new flash drive. You can get a list of devices with lsblk, we presume it’s /dev/sda in this case. For details how to do it, see the previous ALARM installation post here.

Make sure the drive has the same label set as it did before. For previous installation example, this was ROOTFS.

When the drive is repartitioned, mount it at some convenient name.

$ mkdir /media/newflash
$ sudo mount /dev/sda1 /media/newflash

If you didn’t copy the files before, mount the external drive with the backup to an easily accessible directory, for example /media/backup. You can get a list of devices with lsblk again, we presume it’s /dev/sdc in this case.

$ mkdir /media/backup
$ sudo mount /dev/sdc1 /media/backup

Now we copy the backed up system files to the new flash drive.

$ sudo cp -a /mnt/backup/usbbackup/* /mnt/newflash

Now unmount the drives and insert them to the Pogoplug E02.

$ sudo umount /media/backup
$ sudo umount /media/newflash

You can now boot your system again.


  1. http://en.wikipedia.org/wiki/Rsync [return]
  2. Commercial VMWare or free Virtualbox available on https://www.virtualbox.org/ [return]