Automatic backups to external media

All Systems Go

After these preparations, restart the system. The installation has installed a new rule for the udev daemon; the restart ensures that this rule is automatically applied. If you now plug the backup stick into a free USB port, the backup should start automatically. When the stick's LED stops flashing, the backup is finished, and the stick is unmounted. If you leave it plugged in and mount it again manually, you will see the first backup in the directory day.0 in the file manager (Figure 4).

Figure 4: The autobackup script creates a new directory for each backup. You always have different versions of your data at hand.

The script creates additional backups on each subsequent day. On the second day, the content moves from day.0 to day.1 and day.0 contains the most recent backup. This continues for a full seven days – even if you skip individual days. Then the script creates a weekly backup: day.6 becomes week.0. This takes place just once a calendar week; after four weeks, the scheme continues with monthly backups.

When using rsnapshot for a server that runs every day, entries in the crontab ensure an orderly workflow – such as a weekly backup every Sunday evening and a monthly backup on the first of every month. With desktops and laptops that are not consistently used every day, this is unlikely to work. For this reason, it makes sense to start the backup precisely when the backup medium is plugged into the computer.

If you are wondering why backups are so fast from the second day onward and why the disk space used by the backups only increases very slowly even though the files are stored in so many daily and weekly directories: This is the "magic" behind rsync. The tool copies only the changed files. For files that do not change, rsync only creates a link, or more specifically a hard link. Then what looks like a file day.1/home/bablokb/old-text.odt is in reality only a pointer to the location of the file day.0/home/bablokb/old-text.odt and day.1/home/bablokb/old-text.odt on the stick.

The procedure offers a number of advantages. Instead of copying large files via USB, rsync just creates the entry – it's fast and saves a large amount of space. Nevertheless, each daily backup shows you exactly the status of the directories on the backup date. If you want to see what has changed between today and the day before yesterday, just compare day.0/[...]/<file>.txt with day.2/[...]/<file>.txt.

Conclusions

With a little preparation, regular backups are performed automatically. This procedure is particularly recommended for people who are already in the habit of copying their data to an external medium from time to time. As always in the open source world, you can adapt the process to your specific needs.

For example, you could replace the trigger for the backup (inserting the stick) with something else – for a laptop, for example, logging into your home WLAN. The backup should then also logically be created on a network drive.

No matter which method you choose, it is crucial that you make regular backups. Don't forget to check from time to time that the backups do what they promise. In my personal experience, there have been cases where the data were backed up daily to the same magnetic tapes for years. Unfortunately, the tapes were only designed for a low, three-digit number of write cycles, which would have made successful data recovery impossible in an emergency. With modern flash media this scenario is not a worry – but, as the saying goes: It's better to be safe than sorry.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Charly's Column

    The principle behind Rsnapshot is nothing new: use Rsync and SSH to back up files to another computer. What sets Rsnapshot apart is its simple setup and its rich collection of features.

  • Ivman

    Better knowledge of the Linux hotplug system opens the door to to innovation and automation. We’ll show you a custom backup solution for laptop computers.

  • Admin Workshop: Backups with Rsync

    It is often inefficient to fire up a tape drive whenever you need to back up files or restore a backup. The Rsync tool pushes critical files to a second computer, where you can access them easily.

  • Back In Time

    Despite the importance of backups, many users still view the process as too complicated and too inconvenient. Back In Time makes the unloved backup less terrifying.

  • Backup Integrity

    A backup policy can protect your data from malware attacks and system crashes, but first you need to ensure that you are backing up uncorrupted data.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News