sh.zio.backup: add notification for end of backup process
parent
136e180328
commit
dc41ec6fea
|
@ -143,9 +143,9 @@ function invoke_script() {
|
|||
fi
|
||||
|
||||
if [[ "$script_result" == 0 ]]; then
|
||||
trigger_notify "success" "Backup script succeeded: $backup_script_name" "$script_log_path"
|
||||
trigger_notify "success" "Backup succeeded: $backup_script_name" "$script_log_path"
|
||||
else
|
||||
trigger_notify "error" "Backup script failed: $backup_script_name" "$(cat "$script_error_log_path" | sed -e "s/\`//g")" "$script_log_path"
|
||||
trigger_notify "error" "Backup failed: $backup_script_name" "$(cat "$script_error_log_path" | sed -e "s/\`//g")" "$script_log_path"
|
||||
fi
|
||||
|
||||
rm -f "$script_error_log_path"
|
||||
|
@ -301,6 +301,28 @@ function get_secret() {
|
|||
fi
|
||||
}
|
||||
|
||||
function print_time() {
|
||||
((h=${1}/3600))
|
||||
((m=(${1}%3600)/60))
|
||||
((s=${1}%60))
|
||||
|
||||
h_string="hours"
|
||||
m_string="minutes"
|
||||
s_string="seconds"
|
||||
|
||||
[[ $h == 1 ]] && h_string="hour"
|
||||
[[ $m == 1 ]] && m_string="minute"
|
||||
[[ $s == 1 ]] && s_string="second"
|
||||
|
||||
output=""
|
||||
|
||||
[[ $h != "0" ]] && output+="$h $h_string"
|
||||
[[ $m != "0" ]] && output+=" $m $m_string"
|
||||
[[ $s != "0" ]] && output+=" $s $s_string"
|
||||
|
||||
echo $output
|
||||
}
|
||||
|
||||
function start_service() {
|
||||
service="$1"
|
||||
|
||||
|
@ -364,9 +386,10 @@ test_file "$restic_repo_file"
|
|||
test_file "$restic_repo_passwd_file"
|
||||
|
||||
if [[ -z "$1" || -f "$1" ]]; then
|
||||
backup_start_time=$(date +%s)
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
say info "Running backup scripts..."
|
||||
trigger_notify "info" "Backup started" "Running all scripts from '$backup_scripts_dir'"
|
||||
|
||||
if ! [[ "$(ls -A $backup_scripts_dir)" ]]; then
|
||||
die "No scripts found in '$backup_scripts_dir'"
|
||||
|
@ -377,11 +400,13 @@ if [[ -z "$1" || -f "$1" ]]; then
|
|||
done
|
||||
else
|
||||
say info "Running script: $(basename "$1")"
|
||||
trigger_notify "info" "Backup started (manual)" "Running script: \"$1\""
|
||||
|
||||
invoke_script "$1"
|
||||
fi
|
||||
|
||||
backup_end_time=$(( $(date +%s) - $backup_start_time ))
|
||||
trigger_notify "info" "Backup completed" "Took $(print_time $backup_end_time)"
|
||||
|
||||
say primary "$(repeat "-" 80)"
|
||||
|
||||
invoke_restic snapshots \
|
||||
|
|
Loading…
Reference in New Issue