Skip to content

Instantly share code, notes, and snippets.

@shturm
Created March 30, 2017 15:16
Show Gist options
  • Save shturm/9356b207f6ac7b5d4533283c813f6be5 to your computer and use it in GitHub Desktop.
Save shturm/9356b207f6ac7b5d4533283c813f6be5 to your computer and use it in GitHub Desktop.
linux-restore-commands.sh
# 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 > "ssd_sda_`date '+%Y%m%d'`.img.gz"
# 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"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment