You are not logged in.
Pages: 1
I am working on a bash script to automate the task of making LVM snapshots doing a backup then removing the snapshot volume. The question I have is how can I get around lvremove asking if I'm sure I want to remove the logical volume, it seems that even with -f (force) it still asks. Here is what I have at the moment
#!/bin/bash
# Backup the system to /mnt (Will later handle LVM snapshots)
if [[ $EUID -ne 0 ]]; then
echo "You must be root!"
exit 1
fi
now=$(date +%Y%m%d)
echo "Doing backup..."
echo "Backing up /dev/system/root"
lvcreate -L 20G -s -n snap /dev/system/root
mount /dev/system/snap /mnt/backup
tar -pczf /backups/root-$now.tar.gz /mnt/backup
umount /mnt/backup
lvremove /dev/system/snap
echo "Backing up /dev/system/home"
lvcreate -L 20G -s -n snap /dev/system/home
mount /dev/system/snap /mnt/backup
tar -pczf /backups/home-$now.tar.gz /mnt/backup
umount /mnt/backup
lvremove /dev/system/snap
echo "Backup Has Finished"
exit 0
The idea is to have the run as a weekly cronjob
Offline
-f works for me. Here's part of my backup script:
echo "Creating LVM snapshot..."
if ! sudo lvcreate --permission r --size 1G --snapshot --name lvm_backup_snapshot /dev/VGSSD1/ArchRoot ; then
echo "Couldn't create snapshot."
exit 1
fi
[ -e ${source_dir} ] || sudo mkdir ${source_dir}
if ! sudo mount -o ro /dev/VGSSD1/lvm_backup_snapshot ${source_dir} ; then
echo "Couldn't mount snapshot."
sudo lvremove -f /dev/VGSSD1/lvm_backup_snapshot
exit 1
fi
...
echo "Removing LVM snapshot..."
sleep 3
sudo umount ${source_dir} && sudo rm -r ${source_dir}
sudo lvremove -f /dev/VGSSD1/lvm_backup_snapshot
I don't remember why I put the sleep 3 in there; I think umount was telling me the device was in use otherwise...
Edit: I'm not running this via cron.
Last edited by stqn (2011-01-21 10:50:36)
Offline
Try the 'yes' command (man yes).
yes | lvremove /dev/system/snap
Offline
Pages: 1