Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- VG_NAME="vg_virtualbox"
- LV_NAME="lv_vms"
- LV_BACKUP_NAME="${LV_NAME}_backup"
- MOUNT_LOCATION="/mnt/${LV_BACKUP_NAME}"
- LVCREATE=$(which lvcreate)
- if [[ $? != 0 ]]; then
- echo "lvcreate not found!"
- exit 1
- fi
- LVREMOVE=$(which lvremove)
- if [[ $? != 0 ]]; then
- echo "lvremove not found!"
- exit 1
- fi
- function pre_backup()
- {
- if [[ -L /dev/$VG_NAME/$LV_BACKUP_NAME ]]; then
- echo "Logical Volume: ${LV_BACKUP_NAME} already exists"
- exit 1
- fi
- $LVCREATE -l100%FREE -s -n $LV_BACKUP_NAME /dev/$VG_NAME/$LV_NAME
- if [[ $? != 0 ]]; then
- echo "lvcreate failed."
- exit 1
- fi
- if [[ ! -d $MOUNT_LOCATION ]]; then
- mkdir -p $MOUNT_LOCATION
- if [[ $? != 0 ]]; then
- echo "Could not create mountpoint: ${MOUNT_LOCATION}"
- exit 1
- fi
- fi
- mount -o ro /dev/$VG_NAME/$LV_BACKUP_NAME $MOUNT_LOCATION
- }
- function post_backup()
- {
- # Do not care about the exit state from umount.
- umount $MOUNT_LOCATION
- if [[ -L /dev/$VG_NAME/$LV_BACKUP_NAME ]]; then
- lvremove -f /dev/$VG_NAME/$LV_BACKUP_NAME
- else
- echo "Logical Volume: ${LV_BACKUP_NAME} not found"
- exit 1
- fi
- }
- if [[ "$1" == "pre" ]]; then
- pre_backup
- elif [[ "$1" == "post" ]]; then
- post_backup
- else
- echo "Usage: $0 <command>"
- echo "Commands available:"
- echo " pre Runs pre backup tasks (create LVM snapshot)"
- echo " post Runs post backup tasks (Delete LVM snapshot)"
- exit -1
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement