Skip to content

Instantly share code, notes, and snippets.

@faizal2007
Created April 24, 2021 16:44
Show Gist options
  • Save faizal2007/f926971809f4554d50f485ececd7f1dd to your computer and use it in GitHub Desktop.
Save faizal2007/f926971809f4554d50f485ececd7f1dd to your computer and use it in GitHub Desktop.
Archive snapshot and delete old copy
#!/bin/bash
VG_GROUP=geekha
LV_NAME=www1-disk
DATE="$(date +%Y_%m_%d-%H%M)"
LV_TAG=snapshot
SIZE=20G
# retention copy
COPY=3
lvcreate -L$SIZE -s -n $LV_NAME-$LV_TAG-$DATE /dev/$VG_GROUP/$LV_NAME
sleep 10
lvdisplay | grep snapshot | grep "LV Path" | grep "${LV_NAME}-snapshot" | sort -r | sed -e '1,'${COPY}'d' | awk '{print $3}' | xargs -n1 -I {} lvremove -y {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment