some fixes
This commit is contained in:
parent
9d79f9f5df
commit
9a7637b7c4
63
btrbk.sh
63
btrbk.sh
|
@ -1,50 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
source config.sh
|
||||
startDate=$(date +%s)
|
||||
|
||||
function main {
|
||||
date=$(date +%Y-%m-%d)
|
||||
month=$(date +%B)
|
||||
month=$(date +%Y-%B)
|
||||
for i in ${!SUBVOLS[@]}; do
|
||||
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
|
||||
echo "backup already run today"
|
||||
continue
|
||||
else
|
||||
btrfs subvolume snapshot -r ${SUBVOLS[$i]} $SNAPDIR$snapName
|
||||
fi
|
||||
if [[ -d "$snapYest" && $bkType = "daily" && $? = 0 ]]; then
|
||||
btrfs send -p $snapYest $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$month/$snapName.pgp
|
||||
if [[ -d "$snapLast" && $bkType = "daily" ]]; then
|
||||
btrfs send -p $snapLast $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$month"-incr/"$snapName.pgp
|
||||
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
|
||||
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 rclone ls $RCLONEDIR$(date -d "$date -6 month" +%Y-%B)-full/; then
|
||||
rclone delete $RCLONEDIR$(date -d "$date -6 month" +%Y-%B)-full/
|
||||
fi
|
||||
|
||||
if [[ $bktype = monthly && "rclone ls $RCLONEDIR$(date -d "$month -1" +B%)" ]]; then
|
||||
for f in `seq 1 2`; do
|
||||
btrfs subvolume delete $SNAPDIR${VOLNAME[$i]}.$(date -d "$date -$f day" +%Y-%m-%d)
|
||||
done
|
||||
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
|
||||
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 {
|
||||
if [ `date +%d` != "01" ]; then
|
||||
bkType=daily
|
||||
|
@ -54,3 +46,20 @@ function testDate {
|
|||
main
|
||||
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