Am 03.09.2010 11:40, schrieb Paul Bijnens: > > Hi Stefan and fellow amanda-users, > > Catching up on my mail... > > Just to confirm that you may post the script. > Anybody even use it and adapt it to his needs. > It's free software (as in "free beer" and in "free speech"). > > Although the script is a bit dated for the current amanda... > (Still need to catch up on that too.)
Ok, thanks, Paul ... I post it with a short explanation: The attached script gets called via crontab before and after amdump. Something like: # create snapshots before amdump 50 20 * * 1-5 /root/bin/make_snapshot_lvm2 -s 2g VG01:amhold:- VG01:vm_data:15g VG01:vm_apps:25g VG01:rsnapshots:- # remove snapshots before users start work 00 07 * * * /root/bin/make_snapshot_lvm2 -r --- You add DLEs like /snap/_mnt_vm_apps where the script mounts the snapshots (under /snap as configured in the script). I use it for some years now and it works very well. Thanks again, Paul, for sharing. Let's see what other amanda-users think of it ... Stefan
#!/bin/sh # Create a snapshot for the backups set -vx USAGE="$0 [-r] [-n] [-s 512m] [VG:LV:size] ..." VERBOSE= REMOVEONLY= DONOTREMOVE= SIZE=512m # default size SNAPTOP=/snap test -d $SNAPTOP || mkdir -p $SNAPTOP || exit 1 while getopts vnrs: i do case $i in v) VERBOSE=verbose ;; n) DONOTREMOVE=donotremove ;; r) REMOVEONLY=removeonly ;; s) SIZE=$OPTARG ;; # default size \?) echo $USAGE exit 2 ;; esac done shift `expr $OPTIND - 1` # SPECS in format 'VG00:LVvar:128m VG00:LVspace:4g VG00::LVother:-' # use size "-" to skip creating a snapshot for that volume SPECS="$*"; PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH; export PATH test -n "$VERBOSE" && lvs --sort lv_name test -n "$VERBOSE" && echo lvs --noheadings --nosuffix --units m --options vg_name,lv_name,lv_size,origin --sort -origin | while read vg_name lv_name lv_size origin do test -n "$VERBOSE" && echo Considering $vg_name $lv_name $lv_size origin=$origin lv__name=`echo $lv_name | sed -e 's/-/--/g'` if [ -n "$origin" -a -z "$DONOTREMOVE" ] then test -n "$VERBOSE" && echo Removing $vg_name $lv_name ## original from Paul: /dev/$vg_name/$lv_name #if test -e /dev/$vg_name/$lv_name && grep "^/dev/$vg_name/$lv_name " /proc/mounts >/dev/null ## SLES: /dev/mapper/VG01-_mnt_vm_apps.2009.05.11T14.33.01.CEST.snap if test -e /dev/$vg_name/$lv_name && grep "^/dev/mapper/$vg_name-$lv_name " /proc/mounts >/dev/null then test -n "$VERBOSE" && echo Killing any processes having files open on $vg_name $lv_name fuser -kvm $SNAPTOP/$lv_name test -n "$VERBOSE" && echo Umounting $vg_name $lv_name umount /dev/$vg_name/$lv_name fi test -n "$VERBOSE" && echo Remove dir $SNAPTOP/$lvname rmdir $SNAPTOP/$lv_name test -n "$VERBOSE" && echo Remove snapshot /dev/$vg_name/$lv_name lvremove -f /dev/$vg_name/$lv_name >/dev/null || { echo Remove Snapshot /dev/$vg_name/$lv_name error exit 1 } continue fi if [ -n "$origin" -o -n "$REMOVEONLY" ] then continue fi mountpoint=`mount | grep "$vg_name-$lv__name" | sed -e 's/.* on //' -e 's/ type .*//'` case $mountpoint in /) continue ;; # snapshots for root fs are not working (??) /tmp) continue ;; # neither for /tmp "") continue ;; # e.g. swap esac vg_free=`vgs --noheadings --options vg_free $vg_name` snapsize=`echo $SPECS | sed -n 's/.*'"$vg_name"':'"$lv_name"':\([^, ]*\).*/\1/p'` if [ "$snapsize" = "-" ] # skip this volume then continue fi test -z $snapsize && snapsize=$SIZE mountpoint=`echo $mountpoint | tr '/' '_'` # Date in ISO 8601 format, see # http://www.iso.ch/iso/en/prods-services/popstds/datesandtime.html # but, colon is a forbidden char for snapshot names, # and hyphens are doubled (could be but ok, creates confusion) # snapname=${mountpoint}.`date +%Y-%m-%dT%H:%M:%S`.snap snapname=${mountpoint}.`date +%Y.%m.%dT%H.%M.%S.%Z`.snap test -n "$VERBOSE" && echo "Creating snapshot $vg_name $lv_name ($snapsize): $snapname" lvcreate --snapshot --size $snapsize --name $snapname \ /dev/$vg_name/$lv_name >/dev/null || { echo Create Snapshot $snapname error exit 1 } snapdir=$SNAPTOP/$snapname mkdir $snapdir rm -f $SNAPTOP/$mountpoint ln -s $SNAPTOP/$snapname $SNAPTOP/$mountpoint # symlink for Amanda test -n "$VERBOSE" && echo Mounting $snapdir mount -o ro /dev/$vg_name/$snapname $snapdir done test -n "$VERBOSE" && echo test -n "$VERBOSE" && lvs --sort lv_name test -n "$VERBOSE" && echo