Skip to content

Instantly share code, notes, and snippets.

@flower1024
Created April 24, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flower1024/bf62d366fd3c792edaac4c2d21272068 to your computer and use it in GitHub Desktop.
Save flower1024/bf62d366fd3c792edaac4c2d21272068 to your computer and use it in GitHub Desktop.
#!/bin/bash
LVS="lv_os_win10"
LVS_TAR="lv_data lv_os_arch"
TARGET="/mnt/data/backup"
for LV in $LVS
do
echo creating snapshot $LV
lvcreate -L50G -s -n backup_$LV /dev/vg/$LV || continue
echo backup
dd if=/dev/vg/backup_$LV bs=1024 | pv -s `lvs /dev/vg/$LV -o LV_SIZE --noheadings --units b --nosuffix` | pigz -c -9 > $TARGET/$LV.gz
echo removing snapshot
lvremove /dev/vg/backup_$LV
echo -------------------------------------------------------
done
for LV in $LVS_TAR
do
echo creating snapshot $LV
lvcreate -L50G -s -n backup_$LV /dev/vg/$LV || continue
echo mounting snapshoot
mkdir -p $TARGET/$LV
mount /dev/vg/backup_$LV $TARGET/$LV
echo backup
tar cf - $TARGET/$LV -P | pv -s $(du -sb $TARGET/$LV | awk '{print $1}') | pigz -c -9 > $TARGET/$LV.gz
echo removing snapshot
umount $TARGET/$LV
lvremove /dev/vg/backup_$LV
echo -------------------------------------------------------
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment