Remove Okiro; moved to file-based definition
All checks were successful
Configure Kumonoboru / deploy (push) Successful in 1m6s
All checks were successful
Configure Kumonoboru / deploy (push) Successful in 1m6s
This commit is contained in:
114
kumonoboru.sh
114
kumonoboru.sh
@@ -9,10 +9,6 @@ show_help()
|
|||||||
echo " {-l|--limit} #[Kbps] -- Limit upload & download speed"
|
echo " {-l|--limit} #[Kbps] -- Limit upload & download speed"
|
||||||
echo " {-v|--verbose} -- Print debug messages"
|
echo " {-v|--verbose} -- Print debug messages"
|
||||||
echo " {-h|--show_help} -- Print this show_help message and exit"
|
echo " {-h|--show_help} -- Print this show_help message and exit"
|
||||||
echo "Available repositories:"
|
|
||||||
echo "Gerbil-TK Photos (path: /var/Red-Vol/Media/Pictures)"
|
|
||||||
echo "Pukeko-XYZ-Containers Containers (path: /var/Red-Vol/Media/Containers)"
|
|
||||||
echo "Pukeko-XYZ-Cloud Data from all devices (path: /var/Red-Vol/Media/Cloud)"
|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
#Pass arguments to the script
|
#Pass arguments to the script
|
||||||
@@ -52,13 +48,13 @@ if [[ -f $PROM_FILE ]]; then
|
|||||||
rm $PROM_FILE
|
rm $PROM_FILE
|
||||||
fi
|
fi
|
||||||
## Monitoring codes:
|
## Monitoring codes:
|
||||||
#+ -3 - failed pruning
|
#+ -3 - failed cleaning
|
||||||
#+ -2 - failed integrity check
|
#+ -2 - failed integrity check
|
||||||
#+ -1 - failed to unlock
|
#+ -1 - failed to unlock
|
||||||
#+ 0 - succesfully backed up
|
#+ 0 - succesfully backed up
|
||||||
#+ 1 - failed backup
|
#+ 1 - failed backup
|
||||||
#+ 2 - passed integrity check
|
#+ 2 - passed integrity check
|
||||||
#+ 3- succesfully pruned
|
#+ 3- succesfully cleaned
|
||||||
|
|
||||||
#Defaults
|
#Defaults
|
||||||
if [[ -z $BWLIMIT ]]; then
|
if [[ -z $BWLIMIT ]]; then
|
||||||
@@ -75,13 +71,13 @@ fi
|
|||||||
|
|
||||||
export B2_ACCOUNT_ID=8582a42a3b99 #Master Key
|
export B2_ACCOUNT_ID=8582a42a3b99 #Master Key
|
||||||
export B2_ACCOUNT_KEY=00041845e8dd29d7e3d091d77bb8a631ee71332be7 #Master Application ID
|
export B2_ACCOUNT_KEY=00041845e8dd29d7e3d091d77bb8a631ee71332be7 #Master Application ID
|
||||||
RESTIC_PASSWORD='f$774$#je4%U8vp8ov*UsZMHqL$m3Smh#fEbbt7hyULQxfnnWmSiS5MEndzVWT$$n^@s$P*o4vV*^rgv3jvvrv@y35VppU$$y*vnG5V@botU&4$39Y6t9HSb3Z548M!4'
|
export RESTIC_PASSWORD='f$774$#je4%U8vp8ov*UsZMHqL$m3Smh#fEbbt7hyULQxfnnWmSiS5MEndzVWT$$n^@s$P*o4vV*^rgv3jvvrv@y35VppU$$y*vnG5V@botU&4$39Y6t9HSb3Z548M!4'
|
||||||
|
|
||||||
|
|
||||||
#Safety function; accepts repository to check
|
#Safety function; accepts repository to check
|
||||||
safety(){
|
safety(){
|
||||||
REPOSITORY="$1"
|
REPOSITORY="$1"
|
||||||
echo -e "Checking if repository is in use - " "$REPOSITORY"
|
echo -e "Checking if repository $REPOSITORY is in use "
|
||||||
#Check no other Restic process is using this repository; Free unnecessary locks, if present
|
#Check no other Restic process is using this repository; Free unnecessary locks, if present
|
||||||
if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
|
if [[ -n $(ps aux | grep restic | grep "$REPOSITORY") ]]; then
|
||||||
echo -e "Repository is in use - ignoring"
|
echo -e "Repository is in use - ignoring"
|
||||||
@@ -115,20 +111,21 @@ backup(){
|
|||||||
check(){
|
check(){
|
||||||
REPOSITORY="$1"
|
REPOSITORY="$1"
|
||||||
PRUNE="$2"
|
PRUNE="$2"
|
||||||
echo -e "Checking integrity (prune: $PRUNE) of repository" "$REPOSITORY"
|
echo -e "Checking integrity (prune: $PRUNE) of repository $REPOSITORY"
|
||||||
## ^ This variable will have value if repo is already clean, indicating
|
## ^ This variable will have value if repo is already clean, indicating
|
||||||
#+ This is a post backup check.
|
#+ This is a post backup check.
|
||||||
if [[ -n $PRUNE ]]; then
|
if [[ -n $PRUNE ]]; then
|
||||||
echo -e "This repository has been cleaned already; will not clean again."
|
echo -e "This repository has been cleaned already; will not clean again."
|
||||||
fi
|
fi
|
||||||
if safety "$REPOSITORY"; then
|
if safety "$REPOSITORY"; then
|
||||||
echo -e "Checking repository health - " "$REPOSITORY"
|
echo -e "Checking health of repository $REPOSITORY"
|
||||||
if restic -r b2:"$REPOSITORY" check --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT"; then
|
if restic -r b2:"$REPOSITORY" check --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT"; then
|
||||||
echo -e "Repository passed integrity check - " "$REPOSITORY"
|
echo -e "Repository $REPOSITORY passed integrity check"
|
||||||
|
echo "system_backup{name=\"$REPOSITORY\"} 2" >> $PROM_FILE
|
||||||
echo -e "Current snapshots:"
|
echo -e "Current snapshots:"
|
||||||
restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG
|
restic -r b2:"$REPOSITORY" snapshots | tee -a $LOG
|
||||||
else
|
else
|
||||||
echo -e "Repository failed integrity check - " "$REPOSITORY"
|
echo -e "Repository $REPOSITORY failed integrity check"
|
||||||
echo "system_backup{name=\"$REPOSITORY\"} -2" >> $PROM_FILE
|
echo "system_backup{name=\"$REPOSITORY\"} -2" >> $PROM_FILE
|
||||||
# code for ^ failed integrity check
|
# code for ^ failed integrity check
|
||||||
|
|
||||||
@@ -141,12 +138,13 @@ clean(){
|
|||||||
if safety "$REPOSITORY"; then
|
if safety "$REPOSITORY"; then
|
||||||
echo -e "Cleaning repository" "$REPOSITORY"
|
echo -e "Cleaning repository" "$REPOSITORY"
|
||||||
if restic -r b2:$REPOSITORY forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT"; then
|
if restic -r b2:$REPOSITORY forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune --limit-upload="$BWLIMIT" --limit-download="$BWLIMIT"; then
|
||||||
echo -e "Repository is trim - " "$REPOSITORY"
|
echo -e "Repository $REPOSITORY is clean"
|
||||||
|
echo "system_backup{name=\"$REPOSITORY\"} 3" >> $PROM_FILE
|
||||||
echo -e "Running post clean check..."
|
echo -e "Running post clean check..."
|
||||||
check "$REPOSITORY" "1"
|
check "$REPOSITORY" "1"
|
||||||
# Marks repository as cleaned already ^ so it won't passed to this function again.
|
# Marks repository as cleaned already ^ so it won't passed to this function again.
|
||||||
else
|
else
|
||||||
echo -e "Failed to prune repository" "$REPOSITORY"
|
echo -e "Failed to clean repository $REPOSITORY"
|
||||||
echo "system_backup{name=\"$REPOSITORY\"} -3" >> $PROM_FILE
|
echo "system_backup{name=\"$REPOSITORY\"} -3" >> $PROM_FILE
|
||||||
# code for ^ failed pruning
|
# code for ^ failed pruning
|
||||||
|
|
||||||
@@ -154,56 +152,44 @@ clean(){
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#If cleaning was forced, or if it's the first of this month - clean.
|
REPO_FILE=".kumonoboru"
|
||||||
if [[ -n $CLEAN ]] || [[ $(date +%d) == "1" ]]; then
|
if [[ ! -f $REPO_FILE ]]; then
|
||||||
check Gerbil-TK
|
echo "Repository file $REPO_FILE is undefined. Please define $REPO_FILE."
|
||||||
clean Gerbil-TK
|
echo "Format:"
|
||||||
check Pukeko-XYZ-Containers
|
echo "[B2-REPOSITORY] [LOCAL_PATH]"
|
||||||
clean Pukeko-XYZ-Containers
|
echo "Example:"
|
||||||
check Pukeko-XYZ-Cloud
|
echo "potato_tmp /tmp/potato"
|
||||||
clean Pukeko-XYZ-Cloud
|
exit 1
|
||||||
|
fi
|
||||||
#If a specific repository was requested, back it up; otherwise, back them all up.
|
if [[ -n $REPOSITORY ]]; then
|
||||||
elif [[ -n $REPOSITORY ]] && [[ -z $CLEAN ]]; then
|
repo_name=$(cat .kumonoboru | grep $REPOSITORY | awk '{print $1}')
|
||||||
case "$REPOSITORY" in
|
repo_path=$(cat .kumonoboru | grep $REPOSITORY | awk '{print $2}')
|
||||||
(Gerbil-TK)
|
if [[ -z $repo_name ]] || [[ -z $repo_path ]]; then
|
||||||
backup Gerbil-TK /var/Red-Vol/Media/Pictures/
|
echo "Could not find repository $REPOSITORY"
|
||||||
;;
|
else
|
||||||
(Pukeko-XYZ-Containers)
|
REPOS["$repo_name"]=$repo_path
|
||||||
backup Pukeko-XYZ-Containers /var/Red-Vol/Media/Containers/
|
fi
|
||||||
;;
|
else
|
||||||
(Pukeko-XYZ-Cloud)
|
declare -A REPOS
|
||||||
backup Pukeko-XYZ-Cloud /var/Red-Vol/Media/Cloud/
|
while read -r repo_entry; do
|
||||||
;;
|
repo_name=$(echo "$repo_entry" | awk '{print $1}')
|
||||||
(*)
|
repo_path=$(echo "$repo_entry" | awk '{print $2}')
|
||||||
show_help;;
|
REPOS["$repo_name"]=$repo_path
|
||||||
esac
|
done < .kumonoboru
|
||||||
|
|
||||||
#If cleaning was not forced, backup the repositories
|
|
||||||
elif [[ -z $CLEAN ]]; then
|
|
||||||
backup Gerbil-TK /var/Red-Vol/Media/Pictures/
|
|
||||||
backup Pukeko-XYZ-Containers /var/Red-Vol/Media/Containers/
|
|
||||||
backup Pukeko-XYZ-Cloud /var/Red-Vol/Media/Cloud/
|
|
||||||
|
|
||||||
#If a specific repository was requested to be cleaned, clean it
|
|
||||||
elif [[ -n $REPOSITORY ]] && [[ -n $CLEAN ]]; then
|
|
||||||
case "$REPOSITORY" in
|
|
||||||
(Gerbil-TK)
|
|
||||||
check Gerbil-TK
|
|
||||||
clean Gerbil-TK
|
|
||||||
;;
|
|
||||||
(Pukeko-XYZ-Containers)
|
|
||||||
check Pukeko-XYZ-Containers
|
|
||||||
clean Pukeko-XYZ-Containers
|
|
||||||
;;
|
|
||||||
(Pukeko-XYZ-Cloud)
|
|
||||||
check Pukeko-XYZ-Cloud
|
|
||||||
clean Pukeko-XYZ-Cloud
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
show_help;;
|
|
||||||
esac
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Wrap up this run's log and report nicely
|
for repo in "${!REPOS[@]}"; do
|
||||||
|
repo_path=${REPOS[$repo]}
|
||||||
|
|
||||||
|
#If cleaning was forced, or if it's the first of this month - clean.
|
||||||
|
if [[ -n $CLEAN ]] || [[ $(date +%d) == "1" ]]; then
|
||||||
|
check $repo
|
||||||
|
clean $repo
|
||||||
|
|
||||||
|
#If a specific repository was requested, back it up; otherwise, back them all up.
|
||||||
|
elif [[ -z $CLEAN ]]; then
|
||||||
|
backup $repo $repo_path
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "All done; have a nice day!"
|
echo "All done; have a nice day!"
|
||||||
Reference in New Issue
Block a user