2018-06-06 17:48:03 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# -*- mode: sh; sh-basic-offset: 2; indent-tabs-mode: nil; -*-
|
|
|
|
# vim: set filetype=sh sw=2 sts=2 expandtab autoindent:
|
2018-06-06 09:51:21 +02:00
|
|
|
#
|
|
|
|
# restic script for backupninja
|
|
|
|
#
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
### HELPERS ###################################################################
|
|
|
|
|
|
|
|
function export_debug {
|
|
|
|
export "$1"="$2"
|
|
|
|
debug "$1=${!1}"
|
|
|
|
}
|
|
|
|
|
|
|
|
### GETCONF ###################################################################
|
|
|
|
|
2018-06-06 09:51:21 +02:00
|
|
|
setsection general
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
getconf run_backup "yes"
|
|
|
|
getconf run_forget "yes"
|
|
|
|
getconf run_check "no"
|
|
|
|
getconf run_prune "no"
|
|
|
|
getconf run_rebuild_index "no"
|
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf cacert
|
|
|
|
getconf cache_dir
|
|
|
|
getconf cleanup_cache
|
|
|
|
getconf json
|
|
|
|
getconf limit_download
|
|
|
|
getconf limit_upload
|
|
|
|
getconf no_cache
|
|
|
|
getconf no_lock
|
|
|
|
getconf option
|
|
|
|
getconf password
|
|
|
|
getconf password_file
|
|
|
|
getconf quiet
|
|
|
|
getconf repository
|
|
|
|
getconf tls_client_cert
|
|
|
|
getconf verbose
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
setsection s3
|
|
|
|
|
|
|
|
getconf aws_access_key_id
|
|
|
|
getconf aws_secret_access_key
|
|
|
|
|
|
|
|
setsection swift
|
|
|
|
|
|
|
|
getconf os_auth_url
|
|
|
|
getconf os_tenant_id
|
|
|
|
getconf os_tenant_name
|
|
|
|
getconf os_username
|
|
|
|
getconf os_password
|
2018-06-07 11:49:18 +02:00
|
|
|
getconf os_region_name
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
setsection b2
|
|
|
|
|
|
|
|
getconf b2_account_id
|
|
|
|
getconf b2_account_key
|
|
|
|
|
|
|
|
setsection azure
|
|
|
|
|
|
|
|
getconf azure_account_name
|
|
|
|
getconf azure_account_key
|
|
|
|
|
|
|
|
setsection gs
|
|
|
|
|
|
|
|
getconf google_project_id
|
|
|
|
getconf google_application_credentials
|
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
### GLOBAL OPTIONS ############################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
[ -z "$repository" ] && \
|
|
|
|
fatal "The repo option must be set."
|
|
|
|
|
|
|
|
[ -z "$password" -a -z "$password_file" ] && \
|
|
|
|
fatal "The password must be set by option 'password' or 'password_file'."
|
|
|
|
|
|
|
|
[ -n "$repository" ] && \
|
|
|
|
cmd_global_options+="--repo $repository "
|
|
|
|
|
|
|
|
[ -n "$password" ] && \
|
|
|
|
export_debug RESTIC_PASSWORD "$password"
|
|
|
|
|
|
|
|
[ -n "$password_file" ] && \
|
|
|
|
cmd_global_options+="--password-file $password_file "
|
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$cacert" ] && \
|
|
|
|
cmd_global_options+="--cacert $cacert "
|
|
|
|
|
|
|
|
[ -n "$cache_dir" ] && \
|
|
|
|
cmd_global_options+="--cache-dir $cache_dir "
|
|
|
|
|
|
|
|
[ -n "$cleanup_cache" ] && \
|
|
|
|
cmd_global_options+="--cleanup-cache "
|
|
|
|
|
|
|
|
[ -n "$json" ] && \
|
|
|
|
cmd_global_options+="--json "
|
|
|
|
|
|
|
|
[ -n "$limit_download" ] && \
|
|
|
|
cmd_global_options+="--limit-download $limit_download "
|
|
|
|
|
|
|
|
[ -n "$limit_upload" ] && \
|
|
|
|
cmd_global_options+="--limit-upload $limit_upload "
|
|
|
|
|
|
|
|
[ -n "$no_cache" ] && \
|
|
|
|
cmd_global_options+="--no-cache "
|
|
|
|
|
|
|
|
[ -n "$no_lock" ] && \
|
|
|
|
cmd_global_options+="--no-lock "
|
|
|
|
|
|
|
|
[ -n "$option" ] && \
|
|
|
|
cmd_global_options+="$(for i in $option; do echo "--option $i "; done)"
|
|
|
|
|
|
|
|
[ -n "$quiet" ] && \
|
|
|
|
cmd_global_options+="--quiet "
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$tls_client_cert" ] && \
|
|
|
|
cmd_global_options+="--tls-client-cert $tls_client_cert "
|
|
|
|
|
|
|
|
[ -n "$verbose" ] && \
|
|
|
|
cmd_global_options+="--verbose $verbose "
|
|
|
|
|
|
|
|
### REPOSITORY ################################################################
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
# SFTP repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "sftp" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
remote="$(echo "$repository" | /usr/bin/awk -F ':' '{print $2}')"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# try SSH connection
|
2018-06-06 17:48:03 +02:00
|
|
|
ssh -q "$remote" exit || \
|
|
|
|
fatal "Cannot connect to '$remote'."
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# REST Server repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "rest" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
remote="${repository#rest:}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# try HTTP connection
|
2018-06-06 17:48:03 +02:00
|
|
|
[ "$(curl -I "$remote" 2>/dev/null | head -n 1 | cut -d$' ' -f2)" == "200" ] || \
|
|
|
|
fatal "Cannot connect to '$remote'."
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Amazon S3 repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "s3" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -z "$aws_access_key_id" -o -z "$aws_secret_access_key" ] && \
|
|
|
|
fatal "Missing some S3 credentials."
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
export_debug AWS_ACCESS_KEY_ID "$aws_access_key_id"
|
|
|
|
export_debug AWS_SECRET_ACCESS_KEY "$aws_secret_access_key"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# OpenStack Swift repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "swift" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 11:49:18 +02:00
|
|
|
[ -z "$os_auth_url" -o -z "$os_tenant_id" -o -z "$os_tenant_name" -o -z "$os_username" -o -z "$os_password" -o -z "$os_region_name" ] && \
|
2018-06-06 17:48:03 +02:00
|
|
|
fatal "Missing some Swift credentials."
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
export_debug OS_AUTH_URL "$os_auth_url"
|
|
|
|
export_debug OS_TENANT_ID "$os_tenant_id"
|
|
|
|
export_debug OS_TENANT_NAME "$os_tenant_name"
|
|
|
|
export_debug OS_USERNAME "$os_username"
|
|
|
|
export_debug OS_PASSWORD "$os_password"
|
2018-06-07 11:49:18 +02:00
|
|
|
export_debug OS_REGION_NAME "$os_region_name"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Backblaze B2 repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "b2" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -z "$b2_account_id" -o -z "$b2_account_key" ] && \
|
|
|
|
fatal "Missing some B2 credentials."
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
export_debug B2_ACCOUNT_ID "$b2_account_id"
|
|
|
|
export_debug B2_ACCOUNT_KEY "$b2_account_key"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Microsoft Azure Blob Storage repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "azure" ]; then
|
|
|
|
|
|
|
|
[ -z "$azure_account_name" -o -z "$azure_account_key" ] && \
|
|
|
|
fatal "Missing some Azure credentials."
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
export_debug AZURE_ACCOUNT_NAME "$azure_account_name"
|
|
|
|
export_debug AZURE_ACCOUNT_KEY "$azure_account_key"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Google Cloud Storage repository
|
2018-06-06 17:48:03 +02:00
|
|
|
if [ "$(echo "$repository" | /usr/bin/awk -F ':' '{print $1}')" == "gs" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -z "$google_project_id" -o -z "$google_application_credentials" ] && \
|
|
|
|
fatal "Missing some Google credentials."
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
export_debug GOOGLE_PROJECT_ID "$google_project_id"
|
|
|
|
export_debug GOOGLE_APPLICATION_CREDENTIALS "$google_application_credentials"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
### BACKUP #####################################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
if [ "$run_backup" == "yes" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
setsection backup
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
getconf include "/"
|
|
|
|
getconf exclude "/dev /lost+found /media /mnt /proc /run /sys /tmp /var/cache /var/lock /var/spool /var/run /var/tmp"
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf exclude_caches
|
|
|
|
getconf exclude_file
|
|
|
|
getconf exclude_if_present
|
|
|
|
getconf files_from
|
|
|
|
getconf force
|
|
|
|
getconf hostname
|
|
|
|
getconf one_file_system
|
|
|
|
getconf parent
|
2018-06-06 11:10:10 +02:00
|
|
|
getconf tag
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf time
|
|
|
|
getconf with_atime
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# prevent bash from expanding glob
|
|
|
|
set -f
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -z "$include" -a -z "$files_from" ] && \
|
|
|
|
fatal "No files or directories specified for backup."
|
|
|
|
|
|
|
|
[ -n "$include" ] && \
|
|
|
|
cmd_options+="$(for i in $include; do echo "$i "; done)"
|
|
|
|
|
|
|
|
[ -n "$files_from" ] && \
|
|
|
|
cmd_options+="$(for i in $files_from; do echo "--files-from $i "; done)"
|
|
|
|
|
|
|
|
[ -d "$repostory" ] && \
|
|
|
|
cmd_options+="--exclude $repository "
|
|
|
|
|
|
|
|
[ -n "$exclude" ] && \
|
|
|
|
cmd_options+="$(for i in $exclude; do echo "--exclude $i "; done)"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ "$exclude_caches" == "yes" ] && \
|
|
|
|
cmd_options+="--exclude-caches "
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$exclude_file" ] && \
|
|
|
|
cmd_options+="$(for i in $exclude_file; do echo "--exclude-file $i "; done)"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$exclude_if_present" ] && \
|
|
|
|
cmd_options+="$(for i in $exclude_if_present; do echo "--exclude-if-present $i "; done)"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ "$force" == "yes" ] && \
|
|
|
|
cmd_options+="--force "
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$hostname" ] && \
|
|
|
|
cmd_options+="--hostname $hostname "
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$one_file_system" ] && \
|
|
|
|
cmd_options+="--one-file-system "
|
|
|
|
|
|
|
|
[ -n "$parent" ] && \
|
|
|
|
cmd_options+="--parent $parent "
|
|
|
|
|
|
|
|
[ -n "$tag" ] && \
|
|
|
|
cmd_options+="$(for i in $tag; do echo "--tag=$i "; done)"
|
|
|
|
|
|
|
|
[ -n "$time" ] && \
|
|
|
|
cmd_options+="--time $time "
|
|
|
|
|
|
|
|
[ "$with_atime" == "yes" ] && \
|
|
|
|
cmd_options+="--with_atime "
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# format command
|
2018-06-06 17:48:03 +02:00
|
|
|
cmd="restic backup ${cmd_global_options//$'\n'}${cmd_options//$'\n'}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# execute backup
|
|
|
|
info "Taking backup snapshot."
|
|
|
|
debug "Running: $cmd"
|
2018-06-06 17:48:03 +02:00
|
|
|
$cmd || \
|
|
|
|
fatal "Restic backup failed."
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# set bash orginal globbing behavior
|
|
|
|
set +f
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd
|
|
|
|
unset cmd_options
|
2018-06-06 09:51:21 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
### FORGET #####################################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
if [[ "$run_forget" == "yes" ]]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
setsection forget
|
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf keep_last "7"
|
|
|
|
getconf keep_hourly
|
|
|
|
getconf keep_daily
|
|
|
|
getconf keep_weekly
|
|
|
|
getconf keep_monthly
|
|
|
|
getconf keep_yearly
|
2018-06-06 11:10:10 +02:00
|
|
|
getconf keep_within
|
|
|
|
getconf keep_tag
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf host
|
|
|
|
getconf tag
|
|
|
|
getconf path
|
|
|
|
getconf compact
|
|
|
|
getconf group_by
|
2018-06-07 11:22:28 +02:00
|
|
|
getconf dry_run
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf prune
|
|
|
|
|
|
|
|
[ -n "$keep_last" ] && \
|
|
|
|
cmd_options+="--keep-last $keep_last "
|
|
|
|
|
|
|
|
[ -n "$keep_hourly" ] && \
|
|
|
|
cmd_options+="--keep-hourly $keep_hourly "
|
|
|
|
|
|
|
|
[ -n "$keep_daily" ] && \
|
|
|
|
cmd_options+="--keep-daily $keep_daily "
|
|
|
|
|
|
|
|
[ -n "$keep_weekly" ] && \
|
|
|
|
cmd_options+="--keep-weekly $keep_weekly "
|
|
|
|
|
|
|
|
[ -n "$keep_monthly" ] && \
|
|
|
|
cmd_options+="--keep-monthly $keep_monthly "
|
|
|
|
|
|
|
|
[ -n "$keep_yearly" ] && \
|
|
|
|
cmd_options+="--keep-yearly $keep_yearly "
|
|
|
|
|
|
|
|
[ -n "$keep_within" ] && \
|
|
|
|
cmd_options+="--keep-within $keep_within "
|
|
|
|
|
|
|
|
[ -n "$keep_tag" ] && \
|
|
|
|
cmd_options+="$(for i in $keep_tag; do echo "--keep-tag=$i "; done)"
|
|
|
|
|
|
|
|
[ -n "$host" ] && \
|
|
|
|
cmd_options+="--host $host "
|
|
|
|
|
|
|
|
[ -n "$tag" ] && \
|
|
|
|
cmd_options+="$(for i in $tag; do echo "--tag=$i "; done)"
|
|
|
|
|
|
|
|
[ -n "$path" ] && \
|
|
|
|
cmd_options+="$(for i in $path; do echo "--path=$i "; done)"
|
|
|
|
|
|
|
|
[ -n "$compact" ] && \
|
|
|
|
cmd_options+="--compact "
|
|
|
|
|
|
|
|
[ -n "$group_by" ] && \
|
|
|
|
cmd_options+="--group-by $group_by "
|
|
|
|
|
2018-06-07 11:22:28 +02:00
|
|
|
[ -n "$dry_run" ] && \
|
|
|
|
cmd_options+="--dry-run "
|
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
[ -n "$prune" ] && \
|
|
|
|
cmd_options+="--prune "
|
2018-06-06 11:10:10 +02:00
|
|
|
|
|
|
|
# format command
|
2018-06-06 17:48:03 +02:00
|
|
|
cmd="restic forget ${cmd_global_options//$'\n'}${cmd_options//$'\n'}"
|
2018-06-06 11:10:10 +02:00
|
|
|
|
|
|
|
# execute forget
|
|
|
|
info "Removing old snapshots based on defined retention policy."
|
|
|
|
debug "Running: $cmd"
|
2018-06-06 17:48:03 +02:00
|
|
|
$cmd || \
|
|
|
|
fatal "Restic forget expired snapshots failed."
|
|
|
|
|
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd
|
|
|
|
unset cmd_options
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
### CHECK ######################################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
if [ "$run_check" == "yes" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
setsection check
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
getconf check_unused
|
|
|
|
getconf read_data
|
|
|
|
getconf read_data_subset
|
|
|
|
getconf with_cache
|
|
|
|
|
|
|
|
[ -n "$check_unused" ] && \
|
|
|
|
cmd_options+="--check-unused "
|
|
|
|
|
|
|
|
[ -n "$read_data" ] && \
|
|
|
|
cmd_options+="--read-data "
|
|
|
|
|
|
|
|
[ -n "$read_data_subset" ] && \
|
|
|
|
cmd_options+="--read-data-subset $read_data_subset "
|
|
|
|
|
|
|
|
[ -n "$with_cache" ] && \
|
|
|
|
cmd_options+="--with-cache "
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# format command
|
2018-06-06 17:48:03 +02:00
|
|
|
cmd="restic check ${cmd_global_options//$'\n'}${cmd_options//$'\n'}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# execute check
|
|
|
|
info "Checking repository integrity and consistency."
|
|
|
|
debug "Running: $cmd"
|
2018-06-06 17:48:03 +02:00
|
|
|
$cmd || \
|
|
|
|
fatal "Restic check repository integrity and consistency failed."
|
|
|
|
|
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd
|
|
|
|
unset cmd_options
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
### PRUNE ######################################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
if [ "$run_prune" == "yes" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# format command
|
2018-06-06 17:48:03 +02:00
|
|
|
cmd="restic prune ${cmd_global_options//$'\n'}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# execute prune
|
|
|
|
info "Removing data not referenced and not needed any more."
|
|
|
|
debug "Running: $cmd"
|
2018-06-06 17:48:03 +02:00
|
|
|
$cmd || \
|
|
|
|
fatal "Restic prune repository failed."
|
|
|
|
|
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
### REBUILD INDEX ##############################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
if [ "$run_rebuild_index" == "yes" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# format command
|
2018-06-06 17:48:03 +02:00
|
|
|
cmd="restic rebuild-index ${cmd_global_options//$'\n'}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-06 11:10:10 +02:00
|
|
|
# execute rebuild-index
|
|
|
|
info "Rebuilding index based on files in the repository."
|
|
|
|
debug "Running: $cmd"
|
2018-06-06 17:48:03 +02:00
|
|
|
$cmd || \
|
|
|
|
fatal "Restic rebuild index repository failed."
|
|
|
|
|
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
### CLEAN UP ###################################################################
|
|
|
|
|
|
|
|
debug "Unsetting environment variables"
|
|
|
|
unset RESTIC_PASSWORD
|
|
|
|
unset AWS_ACCESS_KEY_ID
|
|
|
|
unset AWS_SECRET_ACCESS_KEY
|
|
|
|
unset OS_AUTH_URL
|
|
|
|
unset OS_TENANT_ID
|
|
|
|
unset OS_TENANT_NAME
|
|
|
|
unset OS_USERNAME
|
|
|
|
unset OS_PASSWORD
|
2018-06-07 11:49:18 +02:00
|
|
|
unset OS_REGION_NAME
|
2018-06-06 09:51:21 +02:00
|
|
|
unset B2_ACCOUNT_ID
|
|
|
|
unset B2_ACCOUNT_KEY
|
|
|
|
unset AZURE_ACCOUNT_NAME
|
|
|
|
unset AZURE_ACCOUNT_KEY
|
|
|
|
unset GOOGLE_PROJECT_ID
|
|
|
|
unset GOOGLE_APPLICATION_CREDENTIALS
|
2018-06-06 17:48:03 +02:00
|
|
|
unset cmd_global_options
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
return 0
|