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 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
|
||||||
return 1
|
warn "Repository $REPOSITORY is in use - ignoring"
|
||||||
# ^ If there's a restic process holding the repository, leave it alone.
|
return 1
|
||||||
else
|
# ^ If there's a restic process holding the repository, leave it alone.
|
||||||
info "Repository $1 is not in use - unlocking"
|
else
|
||||||
restic -r b2:$1 unlock
|
info "Repository $REPOSITORY is not in use - unlocking"
|
||||||
# ^ If a lock exists but no process, the repository is safe and should be unlocked.
|
restic -r b2:$REPOSITORY unlock
|
||||||
fi
|
# ^ 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 function; accepts repository and path to backup
|
||||||
backup(){
|
backup(){
|
||||||
#Check safety
|
REPOSITORY="$1"
|
||||||
if safety $1; then
|
REPOSITORY_PATH="$2"
|
||||||
#Run the backup
|
if safety "$REPOSITORY"; then
|
||||||
if restic -r b2:$1 backup $2; then
|
#Run the backup
|
||||||
ok "Path $2 completed upload to $1." #Running integrity check"
|
if restic -r b2:"$REPOSITORY" backup "$REPOSITORY_PATH"; then
|
||||||
#Run integrity check
|
ok "Path $REPOSITORY_PATH completed upload to $REPOSITORY."
|
||||||
# if restic -r b2:$1 check; then
|
check "$REPOSITORY"
|
||||||
# echo "[OK]: Repository $1 is healthy"
|
else
|
||||||
# Prune repository to avoid unnecessary data
|
error "Repository $REPOSTIORY failed to upload path $REPOSITORY_PATH!"
|
||||||
if restic -r b2:$1 prune; then
|
fi
|
||||||
ok "Repository $1 is trim"
|
fi
|
||||||
else
|
}
|
||||||
error "Failed to prune repository $1!"
|
check(){
|
||||||
fi
|
REPOSITORY="$1"
|
||||||
# else
|
if safety "$REPOSITORY"; then
|
||||||
# echo "[ERR]: Repository $1 failed integrity check!" > /dev/stderr
|
if restic -r b2:"$REPOSITORY" check; then
|
||||||
# fi
|
ok "Repository $REPOSITORY passed integrity check!"
|
||||||
else
|
clean "$REPOSITORY"
|
||||||
error "Repository $1 failed to upload path $2!"
|
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
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
#Pictures
|
#Pictures
|
||||||
backup Gerbil-TK /Red-Vol/Media/Pictures/
|
backup Gerbil-TK /Red-Vol/Media/Pictures/
|
||||||
|
|||||||
Reference in New Issue
Block a user