Michaela Merz's personal blog site

Forward – into the past

If you’re like me, you’re not too crazy about backups. But stuff will happen. And it did to me.  I thought it might be time to help you people out there with a tool that actually allows you to go back in time to correct errors you may have committed in the digital ‘now’.

I am sure – some people are as foolish as I am. For example: I am coding stuff. I have a brilliant idea only to find out -after a couple of days- that my brilliant idea was just a brain fart. Sure, a few changes were actually great, but now that I am totally lost I wish I would have saved a lot more iterations of the source-code in between. If you have a fancy IDE, you may be able to punch “UNDO” ’till the finger hurts. But I have actually seen and experienced crashed IDEs destroying the work of a month in a blink of an eye.

Back to my source. I have a backup. Of course. But its a few days old before I started with the modifications. I would need just say a day or just  few hours back .. just before I destroyed all the real smart changes by trying to make it perfect.

Ups – I did it again.

If one could only go back in time. Well – actually – one can. This is why God (or Steve Jobs or both) invented the ‘Time Machine’ – or ‘rsync’ – as we poor Linux/Unix people happen to call it.

Since a few months now my computer automatically generates 30 Minutes ‘snapshots’ of my workspace – my ~/ and of course ~/Desktop.

All I’ve got to do is:

Access the backup disk, locate the right folder, copy the old source back to where it belongs (at that time, one should have renamed the screwed up source). Done.

It’s magic.

/me is bowing to the developers of rsync

A smart combination of copying files and hard-linking, the ‘time machine’ rsync process doesn’t need a lot of space, since it usually copies data only once and hard-links it’s newer siblings. As long as you don’t change (overwrite, delete) data, snapshots won’t use any space at all (well, a few hard links). So you can go way back  into the past.

To make a long story short: Here’s my script:

#!/bin/sh
date=`date "+%Y-%m-%dT%H:%M:%S"`
tmpath="TimeMachine_ABEDFG"
tosave="/home/myHomeDir"

echo "---------------------------------------------" >> /tmp/time-machine.log
echo $date >> /tmp/time-machine.log

path=`find /media -name $tmpath`
if [ -d "$path" ] ; then
rsync --max-size=5G -aP --link-dest=$path/current $tosave $path/back-$date 2>> /tmp/time-machine.log | grep speedup >> /tmp/time-machine.log
rm -f $path/current
ln -s $path/back-$date $path/current
exit
fi
echo "Disk not available" >> /tmp/time-machine.log

A little more information:

I created a subdirectory “TimeMachine_ABEDFG” on my USB backup-disk. After the start of the script, ‘find’ looks in /media for this directory and, if it is found returns the full path. We’re ready to snapshot. If it’s not found, the backup disk isn’t available and we terminate.

This script is called via ‘cron’ and, well that is that.More information is available via

man rsync

Please take a week of vacation before you actually try to understand the greatness of rsync.

Oh .. by the way: It is actually a smart idea to encrypt your backup disks. They tend to get lost 🙂

 

Leave a Reply

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