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