NONparametrics

geekdom without assumption
NONparametrics

Back to the classics: rsync

If you haven’t read my post about using RAID1 with an external USB drive, don’t bother. I followed the steps as laid out in the guides that I had found, but a couple hours of wrestling with it ended with the realization that booting Maverick on a degraded RAID array with encryption on top just wasn’t going to happen. With a little more consideration, I realized that I would still need a backup solution, since RAID doesn’t mitigate the risk of file corruption or accidental deletion. Aside from that, it would be awfully nice to have snapshot-style history, in case I made an erroneous change and overwrote something important.


Any Mac users out there are likely gloating about their Time Machine (a great move for Apple), but even if I could have that, there is one major reason I would not: the only way to access that history is to restore the entire computer–which is great, if after your computer is [stolen/dropped out a window/filled with a latte] you have either a) have an extra up-to-date Mac with no data sitting around, or b) lots of extra cash to go buy one. I’d rather be able to grab my data immediately with one of my other machines.

There are a few tools out there that provide a TimeMachine-like backup and interface for Linux, but it seems that none of them is extremely well maintained; some I looked at even refused to install on 64-bit distros. If you want to check those out, Flyback and Timevault are two of the more popular. Neither had both the features and recent development activity.

Running out of time to spend on this issue, I did a few searches on rsync (the component/tool that powers most of the good backup systems) and stumbled across this site about Backing up with Rsync. It’s not the prettiest, but there is a lot of good information. I learned a lot about rsync, most of which hasn’t changed in the last 10 years. All of that let me to write a very simple script for making snapshots of my disk using rsync and hard links.

This simple but elegant solution gives me snapshot backups with ease, and it’s portable. I can plug my portable hard drive into any machine with dm_crypt and rsync (most POSIX OSes), type in my encryption pass-phrase, and then run my script to back it up or browse the snapshots of my other backups. It’s old school, but it’s the best I’ve got.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
 
BU_TO_DIR=/media/[portable_disk]
EXCLUDE=/.bu_excludes
DIR_PREFIX=$(hostname)
CURRENT=$BU_TO_DIR/$DIR_PREFIX.$(date +%Y%m%d_%H%M)
 
 
echo "starting backup -- $(date +%Y%m%d %H:%M:%S)" >> bu-error.log
if [ ! -d "$BU_TO_DIR"  ]
then
        echo "Backup media not attached:" $BU_TO_DIR
        exit ;
 
fi
if [ -d "$BU_TO_DIR/`ls $BU_TO_DIR | grep $DIR_PREFIX.*  | tail -n1`" ]
then
        LAST=$(ls $BU_TO_DIR | grep $DIR_PREFIX | tail -n1)
        LINK_DEST="--link-dest=$BU_TO_DIR/$LAST"
else
        LINK_DEST=""
        echo "no previous backup, baslineing..."
fi
 
RSYNC_CMD="rsync --archive --one-file-system --hard-links \
  --human-readable --inplace --numeric-ids --delete \
  --delete-excluded --exclude-from=$EXCLUDE \
  --progress --itemize-changes \
  $LINK_DEST \
  / $CURRENT"
 
exec $RSYNC_CMD 2>>bu-error.log

Related Tags: [ , , , ]

3 Responses to “Back to the classics: rsync”

  1. Alyssa says:

    You’re right…I am gloating just a little over my Mac’s Time Machine, even with it’s obvious shortcomings. It’s saved my bacon more than once.

  2. Alyssa says:

    BTW, might be nice to be able to leave a comment on a post when you reach from the homepage…not having to click on the link to the specific post. Just a thought….

  3. Bryan says:

    For analytics purposes, I was considering doing ‘read more’ tags on all the posts on the homepage; right now, I can’t tell if people are finding anything interesting. Also, it helps with deduping content for SEO.

Leave a Reply