Files
duplicati/Duplicati/Library/Snapshots/lvm-scripts/remove-lvm-snapshot.sh
T
kenneth.skovhede@gmail.com 51552bea24 Fixes for issue #18.
Added snapshot support using either VSS (win xp/vista/7) or LVM (linux).
Using the snapshot feature requires administrative/root privileges, and is toggled by the "snapshot-policy" option (by commandline or in advanced settings).

Also improved the validation of options to not show incorrect warnings.
This fixes issue #233.


git-svn-id: https://duplicati.googlecode.com/svn/trunk@461 59da171f-624f-0410-aa54-27559c288bec
2010-08-12 18:32:15 +00:00

83 lines
1.8 KiB
Bash

#!/bin/bash
# This script removes a lvm snapshot, modify as required
#
# Input is always:
# $1 = name of the snapshot, a random name, same as given to create-lvm-snapshot, usually something like "duplicati-0102030011234567"
# $2 = name of the device for which the snapshot was created, same as given to create-lvm-snapshot, usually a LVM id like "vg_name/lv_name"
# $3 = name of the temporary folder reported by create-lvm-snapshot, usually "/tmp/duplicati-0102030011234567"
NAME=$1
DEVICE=$2
TMPDIR=$3
#
# Get the reported mount point for the temp folder
#
VOLUME=`df -P "$TMPDIR" | tail -1 | awk '{ print $1}'`
if [ "$?" -ne 0 ]
then
EXIT_CODE=$?
echo "Error: unable to determine mount point for $TMPDIR"
exit $EXIT_CODE
fi
#
# Get the LVMID for the temp folder
#
LVMID=`lvs "$VOLUME" --options vg_name,lv_name --noheadings | tail -1 | awk '{ print $1 "/" $2}'`
if [ "$?" -ne 0 ]
then
EXIT_CODE=$?
echo "Error: unable to determine LVM id for $VOLUME"
exit $EXIT_CODE
fi
LVM_ORIGIN=`lvs "$LVMID" --noheadings --options origin | tail -1 | awk '{print $LF}'`
if [ "$?" -ne 0 ]
then
EXIT_CODE=$?
echo "Error: unable to determine LVM origin for $LVMID"
exit $EXIT_CODE
fi
if [ -z "$LVM_ORIGIN" ]
then
echo "Error: The origin of $LVMID is empty, indicating it is NOT a shapshot, aborting!"
exit -1
fi
umount -f "$TMPDIR"
if [ "$?" -ne 0 ]
then
echo "Error: umount -f \"$TMPDIR\" failed!"
echo "Waiting 5 seconds before retry"
sleep 5
umount -f "$TMPDIR"
EXIT_CODE=$?
if [ "$?" -ne 0 ]
then
echo "Error: umount -f \"$TMPDIR\" failed twice!"
exit $EXIT_CODE
fi
fi
lvremove --force "$LVMID"
if [ "$?" -ne 0 ]
then
EXIT_CODE=$?
echo "Error: lvremove failed: lvremove --force \"$LVMID\""
exit $EXIT_CODE
fi
rmdir "$TMPDIR"
if [ "$?" -ne 0 ]
then
EXIT_CODE=$?
echo "Error: rmdir \"$TMPDIR\" failed!"
exit $EXIT_CODE
fi
exit 0