|
|
|
|
@@ -44,6 +44,22 @@ flags()
|
|
|
|
|
}
|
|
|
|
|
flags "$@"
|
|
|
|
|
|
|
|
|
|
#File to write results to; picked up by Prometheus and yells about changes
|
|
|
|
|
PROM_FILE="$CONTAINER_DIR/prometheus/data/kumonoboru.prom"
|
|
|
|
|
|
|
|
|
|
#Remove log from last runs, if present
|
|
|
|
|
if [[ -f $PROM_FILE ]]; then
|
|
|
|
|
rm $PROM_FILE
|
|
|
|
|
fi
|
|
|
|
|
## Monitoring codes:
|
|
|
|
|
#+ -3 - failed pruning
|
|
|
|
|
#+ -2 - failed integrity check
|
|
|
|
|
#+ -1 - failed to unlock
|
|
|
|
|
#+ 0 - succesfully backed up
|
|
|
|
|
#+ 1 - failed backup
|
|
|
|
|
#+ 2 - passed integrity check
|
|
|
|
|
#+ 3- succesfully pruned
|
|
|
|
|
|
|
|
|
|
#Defaults
|
|
|
|
|
if [[ -z $BWLIMIT ]]; then
|
|
|
|
|
export BWLIMIT="0"
|
|
|
|
|
@@ -69,7 +85,8 @@ safety(){
|
|
|
|
|
#Check no other Restic process is using this repository; Free unnecessary locks, if present
|
|
|
|
|
if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
|
|
|
|
|
echo -e "Repository is in use - ignoring"
|
|
|
|
|
return 1
|
|
|
|
|
echo "system_backup{name=\"$REPOSITORY\"} -1" >> $PROM_FILE
|
|
|
|
|
return 1 # code for ^ failed to unlock
|
|
|
|
|
# ^ If there's a restic process holding the repository, leave it alone.
|
|
|
|
|
else
|
|
|
|
|
echo -e "Repository is not in use - unlocking"
|
|
|
|
|
@@ -87,8 +104,10 @@ backup(){
|
|
|
|
|
echo -e "Backing up repository" "$REPOSITORY"
|
|
|
|
|
if restic --cache-dir="$RESTIC_CACHE_DIR" -r b2:"$REPOSITORY" backup "$REPOSITORY_PATH" --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT"; then
|
|
|
|
|
echo -e "$REPOSITORY_PATH" "completed upload to $REPOSITORY."
|
|
|
|
|
echo "system_backup{name=\"$REPOSITORY\"} 0" >> $PROM_FILE
|
|
|
|
|
else
|
|
|
|
|
echo -e "$REPOSITORY failed to upload path" "$REPOSITORY_PATH"
|
|
|
|
|
echo "system_backup{name=\"$REPOSITORY\"} 1" >> $PROM_FILE
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
@@ -110,6 +129,9 @@ check(){
|
|
|
|
|
restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG
|
|
|
|
|
else
|
|
|
|
|
echo -e "Repository failed integrity check - " "$REPOSITORY"
|
|
|
|
|
echo "system_backup{name=\"$REPOSITORY\"} -2" >> $PROM_FILE
|
|
|
|
|
# code for ^ failed integrity check
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
@@ -125,6 +147,9 @@ clean(){
|
|
|
|
|
# Marks repository as cleaned already ^ so it won't passed to this function again.
|
|
|
|
|
else
|
|
|
|
|
echo -e "Failed to prune repository" "$REPOSITORY"
|
|
|
|
|
echo "system_backup{name=\"$REPOSITORY\"} -3" >> $PROM_FILE
|
|
|
|
|
# code for ^ failed pruning
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
@@ -181,4 +206,4 @@ elif [[ -n $REPOSITORY ]] && [[ -n $CLEAN ]]; then
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
#Wrap up this run's log and report nicely
|
|
|
|
|
echo "All done; have a nice day!"
|
|
|
|
|
echo "All done; have a nice day!"
|