[snapshot-rootfs] added configuration options + ask to remove last snapshot

This commit is contained in:
masq 2024-11-04 09:56:54 +01:00
parent 735fecf95e
commit c9ecf555c8
Signed by: masq
GPG Key ID: 35A0D64DDE13B10F
1 changed files with 32 additions and 4 deletions

View File

@ -1,8 +1,36 @@
#!/usr/bin/bash #!/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` 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