sanity checks
This commit is contained in:
parent
220a653d53
commit
9d79f9f5df
40
btrbk.sh
40
btrbk.sh
|
@ -1,26 +1,27 @@
|
|||
#!/bin/bash
|
||||
|
||||
source config.sh
|
||||
set -euo pipefail
|
||||
|
||||
function main {
|
||||
date=$(date +%Y-%m-%d)
|
||||
month=$(date +%B)
|
||||
for i in ${!SUBVOLS[@]}
|
||||
do
|
||||
for i in ${!SUBVOLS[@]}; do
|
||||
snapName=${VOLNAME[$i]}.$date
|
||||
snapYest=$SNAPDIR${VOLNAME[$i]}.$(date -d "$date -1 day" +%Y-%m-%d)
|
||||
if [[ -d "$SNAPDIR$snapName" ]]; then
|
||||
echo "backup already run today"
|
||||
continue
|
||||
else
|
||||
btrfs subvolume snapshot -r ${SUBVOLS[$i]} $SNAPDIR$snapName
|
||||
if [[ -d "$snapYest" && $bkType = "daily" && $? -ne 0 ]]
|
||||
then
|
||||
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
|
||||
else
|
||||
btrfs send $SNAPDIR$snapName | gpg --batch -er $PUBKEY -o - | rclone rcat $RCLONEDIR$snapName.pgp
|
||||
fi
|
||||
if [[ $bktype = monthly ]]
|
||||
then
|
||||
for f in `seq 1 2`
|
||||
do
|
||||
|
||||
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)/
|
||||
|
@ -30,11 +31,26 @@ function main {
|
|||
done
|
||||
}
|
||||
|
||||
if [ `date +%d` != "01" ]
|
||||
then
|
||||
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
|
||||
main
|
||||
else
|
||||
bkType=monthly
|
||||
main
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue