Wednesday 13 June 2007

Backing up your home to DVD with debian

I've finally got a DVD writer (external - it's a laptop) and it works quite amazingly well: no setup issues at all!

Now, the whole point of the exercise was that my Dell is getting a little dodgy (you have to press down hard around the power button to flex the PCB below in order to get it to boot!) and I wanted to back up my documents, sourcecode, emails etc. in case the worst should befall my poor old laptop. But I had a German exam the next day, and while I was burning the DVD I should also be revising!

In general, burning a data DVD on linux is easy. You get a copy of mkisofs and growisofs (on debian, this is easy: apt-get install dvd+rw-tools mkisofs). Then you call mkisofs on a directory tree to create an iso image (put it in /tmp!) and growisofs to write the lot to your DVD (I got the instructions here

Ahah, but not so fast! I wanted to do my home directory whilst xfce, claws-mail, firefox and probably a whole load of other processes were writing tiddly little bits to all my hidden dot-files and dot-directories in ~/ (you know, the ones like ~/.gnome and ~/.mozilla etc.). In fact, I didn't twig the first time and mkisofs threw a wobbly! Moreover, I didn't want to make another copy of everything because there's quite a lot of stuff and I didn't really have space for that on the harddisk partition.

So here's the solution:

First I made a folder called backmeup in my home directory:
mkdir backmeup
Then I moved all of the "normal" i.e. non-hidden files in my home directory into backmeup:
mv * backmeup
This will actually complain because at some point you've asked it to move backmeup into backmeup, but ignore the complaint - it did what we wanted! Now for the dot-files. We don't want to move them into backmeup, because some of the running programs would throw a wobbly, so we will actually need to copy this lot. Now, don't run cp -Rp .* backmeup/ because it'll go horribly wrong and try to make two copies of backmeup via the .. directory I think (disclaimer: Yes, this did go horribly wrong. And it took me 5 minutes to notice!)

Instead, call the following command:
cp -Rp `find -maxdepth 1 -name '.*' | sed '/^\.$/d'` backmeup
which is what we really wanted.

Now we're almost done! Just make the iso from the backmeup tree (no-one's going to be writing automatically to something called that!):
nice -n 19 mkisofs -r -o /tmp/rupert.iso /home/rupert/backmeup
The nice command is just to stop the job hogging the whole system.

... And write the iso to the disk:
growisofs -Z /dev/scd0=/tmp/rupert.iso

(clearly the device to which you write will need to depend on what the kernel calls it - I'm trying to do something clever with udev, but haven't quite got there yet!)

No comments: