Skip to content

Instantly share code, notes, and snippets.

@shturm
Last active August 21, 2016 08:31
Show Gist options
  • Save shturm/6da63f9f7250800bf7cabc072a932912 to your computer and use it in GitHub Desktop.
Save shturm/6da63f9f7250800bf7cabc072a932912 to your computer and use it in GitHub Desktop.

Restore a complete copy of the SSD (sda device)

gunzip -c /media/data/IMAGE_NAME.img.tgz | dd of=/dev/sda

Create and compress complete backup of sda (the SSD) disk

dd if=/dev/sda conv=sync,noerror bs=1k | gzip -c > IMAGE_NAME.img.tgz

Remove LVM the snapshot

sudo lvremove /dev/ubuntuvg/rootsnap

Create LVM snapshot

sudo lvcreate -s -n rootsnap --size 10G /dev/ubuntuvg/rootlv

Rollback LV changes to the snapshot. Must reboot to take effect

sudo lvconvert --merge ubuntuvg/rootsnap

Add cron job to check every hour if the snapshot is full

# m h  dom mon dow   command
23 * */1 * * * sh /home/alx/bin/lvm-check-snapshot.sh

and the content of the script:

PERCENT=$(sudo lvs | grep rootsnap | awk {'print $6'} | egrep -o ^[0-9]{2})
FULLPERCENT=$(sudo lvs | grep rootsnap | awk {'print $6'}
if [ $PERCENT -gt 80 ]
then
    notify-send  "LVM snapshot is almost full: $FULLPERCENT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment