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

Re: Little Cron difficulty I would like help with



On Sun, Nov 20, 2011 at 02:56:52PM +0000, Alan Chandler wrote:
> I have a (daily) cron (actually its anacron - since this is my
> desktop and is powered down every night) job that attempts to take a
> snapshot of a logical volume (it happens to be the one where I store
> embedded virtual machines "disk" files on) to take a backup.
> 
> Almost every day, I get an error with it related to either not being
> able to unmount the snapshot, or the opposite - finding the snapshot
> is already mounted.
> 
> Given the size of the files (~100G) this backup takes quite a while,
> so it could be that I occasionally power off the machine in the
> middle of the process.
> 
> I have attempted to incorporate some advice given in debian bug #54961
> 
> I would like to get some advice on how to make my script more robust.
> 
> Here is the relevant part of the backup script
> 
> logger -t "Backup:" "Backing up Virtual Machine Images"
> 
> lvcreate -L 40G -n vm-backup -s /dev/raid/VBVM
> mkdir -p /mnt/vm-backup
> mount /dev/raid/vm-backup /mnt/vm-backup
> rsync -aq --delete --inplace /mnt/vm-backup/
> owl:/bak/alan/backup/"VirtualBox VM
> s"/
> umount /dev/raid/vm-backup
> # All this to remove the snapshot - see Debian Bug #549691
> sleep 10
> sync
> sleep 10
> dmsetup remove /dev/mapper/raid-vm--backup
> dmsetup remove /dev/mapper/raid-vm--backup-cow
> lvremove -f /dev/raid/vm-backup
> 
> 
> In writing this post I have been looking at the debian bug reports -
> starting with 549691 mentioned above.  There are several versions of
> the bug in lvm2 around, but I can't understand if there is any
> reaction from someone who is maintaining lvm2.  As far as I can tell
> there is one comment in #618016 saying this is not the latest
> version please upgrade, but then a slew of reports following that
> saying that they were at the latest version and its still
> reproduceable.
> 
> Does anyone else know about this problem and what should be done to
> get around it.

I think I would start by making sure the system is in a known state
before beginning your work.

At the moment you're:
 * Creating a Snapshot
 * Mounting the snapshot
 * Performing the backup
 * Unmounting the snapshot
 * Removing the snapshot

However, as you've mentioned, sometimes you may shut down the machine in
the middle of step 3. This, presumably, leaves you with the snapshot
still in existance, so step 1 will error.

Instead, try the following recipe:
 * Unmount the snaphot
 * Remove the snapshot
 * Create the snapshot
 * Perform the backup
 * Unmount the snapshot
 * Remove the snapshot

What you're doing then, is ensuring that you're in a known state
beforehand; if the snapshot is not mounted or the snapshot LVM does not
exists, you ignore the error (perhaps redirect it to /dev/null if it
bothers you), if they do, they get cleaned up.


-- 
Darac Marjal

Attachment: signature.asc
Description: Digital signature


Reply to: