From c9ecf555c89ec9b5c16bb98d804b2398a035241b Mon Sep 17 00:00:00 2001 From: masq Date: Mon, 4 Nov 2024 09:56:54 +0100 Subject: [PATCH] [snapshot-rootfs] added configuration options + ask to remove last snapshot --- snapshot-rootfs.sh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/snapshot-rootfs.sh b/snapshot-rootfs.sh index 7ec50b3..afaae0b 100755 --- a/snapshot-rootfs.sh +++ b/snapshot-rootfs.sh @@ -1,8 +1,36 @@ #!/usr/bin/bash +# snapshot-rootfs.sh +# +# In your /etc/profile, export the following variables +# LVM_VG_ROOTFS=vg0 +# LVM_LG_ROOTFS_NAME=rootfs-arch +# LVM_ROOTFS_SNAPSHOT_SZ=10G +source /etc/profile + +crash() { + echo $1; + exit 1; +} + +[ \ + -n "$LVM_VG_ROOTFS" \ + -a -n "$LVM_LG_ROOTFS_NAME" \ + -a -n "$LVM_ROOTFS_SNAPSHOT_SZ" \ +] || crash "Missing one of the LVM variables for snapshot-rootfs.sh"; -VG=vg0 -ROOTFS=rootfs-arch -SZ=10G DATE=`date +%Y%m%dT%H%M` -lvcreate -n $ROOTFS-$DATE --snapshot -L $SZ $VG/$ROOTFS +LAST_SNAPSHOT_NAME=`lvs --select "origin = $LVM_LG_ROOTFS_NAME" \ + --noheadings -o "data_percent,lv_name" 2>&1 \ + |sort -n|grep -o '[^[:space:]]\+$'` + +echo "The last snapshot's name is : $LAST_SNAPSHOT_NAME. Remove it? (y/n)" + +read REMOVE_LAST_SNAPSHOT + +[ $REMOVE_LAST_SNAPSHOT = "y" ] && lvremove $LVM_VG_ROOTFS/$LAST_SNAPSHOT_NAME + +lvcreate -n $LVM_LG_ROOTFS_NAME-$DATE \ + --snapshot \ + -L $LVM_ROOTFS_SNAPSHOT_SZ $LVM_VG_ROOTFS/$LVM_LG_ROOTFS_NAME +