diff --git a/conf/backup_method b/conf/backup_method index de6cb58..d172cc2 100644 --- a/conf/backup_method +++ b/conf/backup_method @@ -1,13 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash +set -Eeuo pipefail -set -eo pipefail -source __INSTALL_DIR__/venv/bin/activate +source "__INSTALL_DIR__/venv/bin/activate" +app="__APP__" -app="${0#"./05-"}" -app="${app%"_app"}" +BORG_PASSPHRASE="$(yunohost app setting "$app" passphrase)" +repo="$(yunohost app setting "$app" repository)" #$4 -BORG_PASSPHRASE="$(yunohost app setting $app passphrase)" -repo="$(yunohost app setting $app repository)" #$4 if ssh-keygen -F "__SERVER__" >/dev/null ; then BORG_RSH="ssh -i /root/.ssh/id_${app}_ed25519 -oStrictHostKeyChecking=yes " else @@ -20,11 +19,10 @@ do_need_mount() { LOGFILE=/var/log/backup_borg.err log_with_timestamp() { - sed -e "s/^/[$(date +"%Y-%m-%d_%H:%M:%S")] /" | tee -a $LOGFILE + sed -e "s/^/[$(date +"%Y-%m-%d_%H:%M:%S")] /" | tee -a $LOGFILE } do_backup() { - export BORG_PASSPHRASE export BORG_RSH export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes @@ -37,11 +35,11 @@ do_backup() { pushd "$work_dir" set +e if borg init -e repokey "$repo" ; then - #human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'` - # Speed in Kbps - #speed=1000 - #evaluated_time=$(($size / ($speed * 1000 / 8) / 3600)) - echo "Hello, + # human_size=`echo $size | awk '{ suffix=" KMGT"; for(i=1; $1>1024 && i < length(suffix); i++) $1/=1024; print int($1) substr(suffix, i, 1), $3; }'` + # Speed in Kbps + # speed=1000 + # evaluated_time=$(($size / ($speed * 1000 / 8) / 3600)) + echo "Hello, Your first backup on $repo is starting. @@ -88,7 +86,7 @@ case "$1" in do_backup "$work_dir" "$name" "$repo" "$size" "$description" ;; mount) - do_mount + do_mount "$work_dir" "$name" "$repo" "$size" "$description" ;; *) echo "hook called with unknown argument \`$1'" >&2