Files
scripts/Resticer

62 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
##Simple script to run Restic backups
source $SCRIPTS/Okiru
source /etc/environment
logging Restic
#Safety function; accepts repository to check
safety(){
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(){
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
}
#Pictures
backup Gerbil-TK /Red-Vol/Media/Pictures/
#Containers
backup Pukeko-XYZ-Containers /Red-Vol/Media/Containers
#Cloud
backup Pukeko-XYZ-Cloud /Red-Vol/Media/Cloud/Syncthing