[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Filesystem snapshots



Advice sought on merging LVM snapshots nightly. I think it's on topic for the list and potentially useful for new users reading their way into tarsnap - possibly even on the FAQ.

In order to archive data when constant updating takes place, even just an email INBOX or a SQL database, the data has to stop changing. The frozen unchanging data is the source for the archive and an overspill area, called - very misleadingly - a snapshot, can accumulate written blocks of fresh data. When the archive is finished, the snapshot can be merged back into the original files and deleted.

My instance is a VirtualBox Slackware 14.1 /home partition encrypted with LUKS on LVM2.

In order to make space for an additional temporary partition (space for the snapshot), I rebooted to init level 3 (a command prompt and no X), unmounted /home, reduced the size of the /home filesystem (resize2fs), reduced the size of the /home partition (lvreduce) and expanded the filesystem back to the partition size (resize2fs).

Nightly crontab can now run tarsnap on a read-only partition while my normal activity continues. My root script creates a snapshot of the home partition (lvcreate -s). This allows the home partition to appear to be mounted read-write while the snapshot partition can be mounted read-only and archived (tarsnap --snaptime).

Once the archive is complete, the accumulated new data can be merged back into the /home filesystem (lvconvert --merge) which will automatically remove the snapshot partition and leave the unallocated logical volume space free for the next time.

My puzzle, for which I have no answer and seek advice, is this:

My X system has remained up but logged off throughout this nightly crontab root script, and that's kept files open and updating on /home. The merge has only been queued by the lvconvert command and will only take effect when /home is unmounted and then mounted again. I need to automate closing X, unmounting and remounting /home and starting X again and I can't think how to do that neatly within the crontab root script. I got as far as (killall --user john) which does bring my instance of X down very effectively, but it feels too extreme (and it probably still leaves /home/john in use). My intention is to be able to log in normally and carry on when I arrive at my PC in the morning.

How does anyone on the list handle nightly snapshot archives tidily?