some fixes
This commit is contained in:
parent
9d79f9f5df
commit
9a7637b7c4
65
btrbk.sh
65
btrbk.sh
|
@ -1,50 +1,42 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
source config.sh
|
source config.sh
|
||||||
|
startDate=$(date +%s)
|
||||||
|
|
||||||
function main {
|
function main {
|
||||||
date=$(date +%Y-%m-%d)
|
date=$(date +%Y-%m-%d)
|
||||||
month=$(date +%B)
|
month=$(date +%Y-%B)
|
||||||
for i in ${!SUBVOLS[@]}; do
|
for i in ${!SUBVOLS[@]}; do
|
||||||
snapName=${VOLNAME[$i]}.$date
|
snapName=${VOLNAME[$i]}.$date
|
||||||
snapYest=$SNAPDIR${VOLNAME[$i]}.$(date -d "$date -1 day" +%Y-%m-%d)
|
snapLast=$SNAPDIR${VOLNAME[$i]}.$(date -d "$date -1 day" +%Y-%m-%d)
|
||||||
|
if ! [[ -d "$snapLast" ]]; then
|
||||||
|
snapLast=$SNAPDIR$(ls -a $SNAPDIR | grep ${VOLNAME[$i]}.$(date -d "$date" +%Y-%m)- | tail -n 1)
|
||||||
|
fi
|
||||||
if [[ -d "$SNAPDIR$snapName" ]]; then
|
if [[ -d "$SNAPDIR$snapName" ]]; then
|
||||||
echo "backup already run today"
|
echo "backup already run today"
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
btrfs subvolume snapshot -r ${SUBVOLS[$i]} $SNAPDIR$snapName
|
btrfs subvolume snapshot -r ${SUBVOLS[$i]} $SNAPDIR$snapName
|
||||||
fi
|
fi
|
||||||
if [[ -d "$snapYest" && $bkType = "daily" && $? = 0 ]]; then
|
if [[ -d "$snapLast" && $bkType = "daily" ]]; then
|
||||||
btrfs send -p $snapYest $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$month/$snapName.pgp
|
btrfs send -p $snapLast $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$month"-incr/"$snapName.pgp
|
||||||
else
|
else
|
||||||
btrfs send $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$snapName.pgp
|
btrfs send $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$month"-full/"$snapName.pgp
|
||||||
fi
|
if [[ $bktype = monthly ]] && rclone ls $RCLONEDIR$(date -d "$date -1 month" +%Y-%B)-incr; then
|
||||||
|
rclone delete $RCLONEDIR$(date -d "$date -1 month" +%Y-%B)-incr/
|
||||||
if [[ $bktype = monthly && "rclone ls $RCLONEDIR$(date -d "$month -1" +B%)" ]]; then
|
if rclone ls $RCLONEDIR$(date -d "$date -6 month" +%Y-%B)-full/; then
|
||||||
for f in `seq 1 2`; do
|
rclone delete $RCLONEDIR$(date -d "$date -6 month" +%Y-%B)-full/
|
||||||
btrfs subvolume delete $SNAPDIR${VOLNAME[$i]}.$(date -d "$date -$f day" +%Y-%m-%d)
|
fi
|
||||||
done
|
fi
|
||||||
rclone delete $RCLONEDIR$(date -d "$month -1 month" +%B)/
|
|
||||||
else
|
|
||||||
btrfs subvolume delete $SNAPDIR${VOLNAME[$i]}.$(date -d "$date -2 day" +%Y-%m-%d)
|
|
||||||
fi
|
fi
|
||||||
|
mapfile -t oldSnaps < <(ls -a $SNAPDIR | grep ${VOLNAME[$i]}.\....-..- | head -n -3)
|
||||||
|
for snap in ${!oldSnaps[@]}; do
|
||||||
|
btrfs subvolume delete $SNAPDIR${oldSnaps[$snap]}
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
rclone ls $RCLONEDIR > /dev/null 2>&1
|
|
||||||
if [[ $? = 0 ]]; then
|
|
||||||
gpg --list-key $PUBKEY > /dev/null 2>&1
|
|
||||||
if [[ $? = 0 ]]; then
|
|
||||||
testDate
|
|
||||||
else
|
|
||||||
echo "pubkey wrong or not found exit code: $?"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "rclone dir wrong or not found exit code: $?"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
function testDate {
|
function testDate {
|
||||||
if [ `date +%d` != "01" ]; then
|
if [ `date +%d` != "01" ]; then
|
||||||
bkType=daily
|
bkType=daily
|
||||||
|
@ -54,3 +46,20 @@ function testDate {
|
||||||
main
|
main
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function end {
|
||||||
|
echo "backup finished in $(( ($(date +%s) - startDate) / 60 )) min"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if rclone ls $RCLONEDIR > /dev/null 2>&1; then
|
||||||
|
if gpg --list-key $PUBKEY > /dev/null 2>&1; then
|
||||||
|
testDate
|
||||||
|
else
|
||||||
|
echo "pubkey wrong or not found exit code: $?"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "rclone dir wrong or not found exit code: $?"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in a new issue