[linux-lvm] Backup with snapshots

Stuart D. Gathman stuart at bmsi.com
Thu Jun 21 14:54:54 UTC 2007


I have been manually running this script to make backups of a live 
application system:
-----------lvbackup------------------
#!/bin/sh
if test "$#" -lt 2; then
  echo "Usage: $0 SRCLV DESTDIR"
  exit 2
fi
lvpath="$1"
media="$2"
shift 2
if test -e "${media}/BMS_BACKUP_V1"; then
        :
else
  echo "${media} is not formatted as a backup drive"
  exit 1
fi

lvname="${lvpath##*/}"
lvname="${lvname##*-}"
snapname="${lvname}_SNAP"
snappath="${lvpath}_SNAP"
tmpdir="/mnt/${snapname}"
destdir="${media}/${lvname}/current"

lvcreate -s -L 2G -n "$snapname" "$lvpath" || exit 1
mkdir -p "$tmpdir" "$destdir"
mount -r "$snappath" "$tmpdir"
mount -o remount,rw "${media}"
rsync -ravXHx "$@" "${tmpdir}/" "${destdir}"
umount "$tmpdir"
mount -r -o remount,ro "${media}"
lvremove "$snappath"
---------------------------------------------

My question concerns the last line.  I asks me if I really want
to remove the LV.

1) Is it intended usage to create and destroy snapshots every day like this?
2) Am I missing a step?  Am I supposed to deactivate the snapshot first?
3) If I deactivate it, can I leave it allocated, and will it resync with
   source LV when I reactivate it?
4) Or am I just supposed to use "-f" on the lvremove?  How do I ensure
   that no stray processes still have the LV open.  The umount will fail
   if stray processes are still in the filesystem, but will the lvremove -f
   still fail if something has the block device open?

I just feel nervous turning scripts that change LVs loose in cron, and
want to make it as safe as possible.

-- 
	      Stuart D. Gathman <stuart at bmsi.com>
    Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flammis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.




More information about the linux-lvm mailing list