Cleaning up the syntax, improving the logging, having fun

This commit is contained in:
2021-12-19 19:05:45 +02:00
parent 5b9a71ad0e
commit bf8da2aa5a

View File

@@ -6,40 +6,52 @@ logging Restic
#Safety function; accepts repository to check #Safety function; accepts repository to check
safety(){ safety(){
#Check no other Restic process is using this repository; Free unnecessary locks, if present REPOSITORY="$1"
if [[ -n $(ps aux | grep restic | grep $1) ]]; then #Check no other Restic process is using this repository; Free unnecessary locks, if present
warn "Repository $1 is in use - ignoring" if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
warn "Repository $REPOSITORY is in use - ignoring"
return 1 return 1
# ^ If there's a restic process holding the repository, leave it alone. # ^ If there's a restic process holding the repository, leave it alone.
else else
info "Repository $1 is not in use - unlocking" info "Repository $REPOSITORY is not in use - unlocking"
restic -r b2:$1 unlock restic -r b2:$REPOSITORY unlock
# ^ If a lock exists but no process, the repository is safe and should be unlocked. # ^ If a lock exists but no process, the repository is safe and should be unlocked.
fi fi
} }
#Backup function; accepts repository and path to backup #Backup function; accepts repository and path to backup
backup(){ backup(){
#Check safety REPOSITORY="$1"
if safety $1; then REPOSITORY_PATH="$2"
if safety "$REPOSITORY"; then
#Run the backup #Run the backup
if restic -r b2:$1 backup $2; then if restic -r b2:"$REPOSITORY" backup "$REPOSITORY_PATH"; then
ok "Path $2 completed upload to $1." #Running integrity check" ok "Path $REPOSITORY_PATH completed upload to $REPOSITORY."
#Run integrity check check "$REPOSITORY"
# if restic -r b2:$1 check; then
# echo "[OK]: Repository $1 is healthy"
# Prune repository to avoid unnecessary data
if restic -r b2:$1 prune; then
ok "Repository $1 is trim"
else else
error "Failed to prune repository $1!" error "Repository $REPOSTIORY failed to upload path $REPOSITORY_PATH!"
fi fi
# else fi
# echo "[ERR]: Repository $1 failed integrity check!" > /dev/stderr }
# fi check(){
REPOSITORY="$1"
if safety "$REPOSITORY"; then
if restic -r b2:"$REPOSITORY" check; then
ok "Repository $REPOSITORY passed integrity check!"
clean "$REPOSITORY"
else else
error "Repository $1 failed to upload path $2!" error "Repository $REPOSITORY failed integrity check!"
fi
fi
}
clean(){
REPOSITORY="$1"
if safety "$REPOSITORY"; then
if restic -r b2:"$REPOSITORY" prune; then
ok "Repository $REPOSITORY is trim!"
else
error "Repository $REPOSITORY failed to prune!"
fi
fi fi
fi
} }
#Pictures #Pictures
backup Gerbil-TK /Red-Vol/Media/Pictures/ backup Gerbil-TK /Red-Vol/Media/Pictures/