initial commit

This commit is contained in:
max/sooulix 2025-02-03 02:51:33 +01:00
commit 0ae4ea17ec
3 changed files with 34 additions and 0 deletions

19
backup_lvm.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
DIR=/mnt/backups_filesystems
VG=`echo $0|rev|cut -d_ -f2|rev`;
LV=`echo $0|rev|cut -d_ -f1|rev`;
FREE=`vgs --noheadings $VG --units b|rev|cut -d' ' -f1|rev|cut -dB -f1`;
if [[ "$FREE" -lt 104857600 ]];
then
echo "Not enough space to make snapshot";
exit 1;
fi;
TIMESTAMP=`date +%Y%m%d-%H%M%S`
lvcreate --addtag backup --snapshot --size 100M --name $LV-$TIMESTAMP $VG/$LV > /dev/null
[[ -f "$DIR/$VG_$LV.img" ]] && rm $DIR/$VG_$LV.img
[[ -f "$DIR/$VG_$LV.img.gz" ]] && rm $DIR/$VG_$LV.img.gz
dd if=/dev/$VG/$LV-$TIMESTAMP bs=1024 conv=noerror,sync status=none | gzip -c -9 > $DIR/$VG_$LV.img.gz
lvremove -y $VG/$LV-$TIMESTAMP > /dev/null
exit 0;

5
run_backup_lvm.sh Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/bash
find ~/backup_lvm.d/ -type l | while read file
do
$file
done

10
snapshot_lvm.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
VG="vg0"
TS=`date +%Y%m%dT%H%M%S`
set -xe
while read -r line;
do
DISK=`echo $line|cut -d' ' -f1`
SIZE=`echo $line|cut -d' ' -f2`
lvcreate --snapshot --name "$DISK-$TS" -L $SIZE $VG/$DISK;
done