2018-06-06 17:48:03 +02:00
|
|
|
# -*- 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
|
|
|
### GETCONF ###################################################################
|
|
|
|
|
2018-06-06 09:51:21 +02:00
|
|
|
setsection general
|
|
|
|
|
2021-01-12 00:22:11 +01:00
|
|
|
getconf testconnect yes
|
2021-01-11 23:56:01 +01:00
|
|
|
getconf nicelevel
|
|
|
|
getconf ionicelevel
|
2021-01-11 04:55:37 +01:00
|
|
|
|
2018-06-13 10:32:19 +02:00
|
|
|
getconf run_backup "no"
|
|
|
|
getconf run_forget "no"
|
2018-06-07 10:42:26 +02:00
|
|
|
getconf run_check "no"
|
|
|
|
getconf run_prune "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
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
setsection s3
|
|
|
|
|
|
|
|
getconf aws_access_key_id
|
|
|
|
getconf aws_secret_access_key
|
2018-08-09 11:35:49 +02:00
|
|
|
getconf aws_session_token
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-01-11 23:56:01 +01:00
|
|
|
# Check that the ionicelevel is valid
|
|
|
|
if [ -n "$nicelevel" ] && { [ "$nicelevel" -lt -20 ] || [ "$nicelevel" -gt 19 ]; }; then
|
|
|
|
fatal "The value of nicelevel is expected to be either empty or an integer from -20 to 19. Got: $nicelevel"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that the ionicelevel is valid
|
|
|
|
if [ -n "$ionicelevel" ] && echo "$ionicelevel" | grep -vq "^[0-7]$"; then
|
|
|
|
fatal "The value of ionicelevel is expected to be either empty or an integer from 0 to 7. Got: $ionicelevel"
|
|
|
|
fi
|
|
|
|
|
2018-07-04 13:06:45 +02:00
|
|
|
### HELPERS ###################################################################
|
|
|
|
|
|
|
|
function export_debug {
|
|
|
|
export "$1"="$2"
|
|
|
|
debug "$1=${!1}"
|
|
|
|
}
|
|
|
|
|
2021-01-11 04:55:37 +01:00
|
|
|
function test_sftp_connection() {
|
|
|
|
local remote
|
|
|
|
local sftpport
|
|
|
|
local output
|
|
|
|
local ret
|
|
|
|
|
|
|
|
remote=$1
|
|
|
|
|
|
|
|
if echo "$remote" | grep -q ':[0-9]\+$'; then
|
|
|
|
sftpport="-P $(echo $remote | @AWK@ -F ':' '{print $2}') "
|
|
|
|
remote=$(echo $remote | @AWK@ -F ':' '{print $1}')
|
|
|
|
fi
|
|
|
|
|
|
|
|
debug "echo | sftp -o PasswordAuthentication=no ${sftpport}${remote}"
|
|
|
|
output=$(echo | sftp -o PasswordAuthentication=no ${sftpport}${remote})
|
|
|
|
ret=$?
|
|
|
|
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
|
|
debug "Connection test to SFTP backend ${remote} succeeded."
|
|
|
|
else
|
|
|
|
debug $output
|
|
|
|
fatal "Failed connecting to SFTP backend at ${remote}."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_rest_connection() {
|
|
|
|
local remote
|
|
|
|
local output
|
|
|
|
local ret
|
|
|
|
|
|
|
|
local remote=$1
|
|
|
|
|
|
|
|
if [ ! -x $(which wget) ]; then
|
|
|
|
error "Unable to test REST connection, wget executable not found!"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
debug "wget --tries=1 --method=HEAD \"${remote}/config\""
|
|
|
|
output=$(wget --tries=1 --method=HEAD "${remote}/config")
|
|
|
|
ret=$?
|
|
|
|
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
|
|
debug "Connection test to REST backend at ${remote} succeeded."
|
|
|
|
elif [ $ret -eq 8 ]; then
|
|
|
|
debug $output
|
|
|
|
fatal "REST backend at ${remote} returned an error, repository may not be created."
|
|
|
|
else
|
|
|
|
debug $output
|
|
|
|
fatal "Failed connecting to REST backend at ${remote}."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-11 23:56:01 +01:00
|
|
|
### PRE-COMMANDS ##############################################################
|
|
|
|
|
|
|
|
[ -n "$nicelevel" ] && \
|
|
|
|
precmd+="nice -n $nicelevel "
|
|
|
|
|
|
|
|
[ -n "$ionicelevel" ] && \
|
|
|
|
precmd+="ionice -c2 -n $ionicelevel "
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-06 17:48:03 +02:00
|
|
|
### GLOBAL OPTIONS ############################################################
|
|
|
|
|
2018-06-07 10:42:26 +02:00
|
|
|
[ -z "$repository" ] && \
|
2021-01-10 04:16:05 +01:00
|
|
|
fatal "The repository option must be set."
|
2018-06-07 10:42:26 +02:00
|
|
|
|
2018-06-07 12:12:09 +02:00
|
|
|
[ -z "$password" ] && [ -z "$password_file" ] && \
|
2018-06-07 10:42:26 +02:00
|
|
|
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" ] && \
|
2018-08-09 11:23:04 +02:00
|
|
|
cmd_global_options+="$(for i in "${option[@]}"; do echo "--option $i "; done)"
|
2018-06-06 17:48:03 +02:00
|
|
|
|
|
|
|
[ -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 "
|
|
|
|
|
|
|
|
### REPOSITORY ################################################################
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
# SFTP repository
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "sftp" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 04:55:37 +01:00
|
|
|
# connection test
|
|
|
|
if [ "$testconnect" = "yes" ] || [ "$test" -eq 1 ]; then
|
|
|
|
|
|
|
|
if echo "$repository" | grep -q '^sftp://'; then
|
|
|
|
remote=$(echo "$repository" | @AWK@ -F '//' '{print $2}')
|
|
|
|
elif echo "$repository" | grep -q '^sftp:'; then
|
|
|
|
remote=$(echo "$repository" | @AWK@ -F ':' '{print $2}')
|
|
|
|
fi
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 04:55:37 +01:00
|
|
|
[ -n "$remote" ] || fatal "Unable to parse SFTP repository URL ${repository}."
|
|
|
|
test_sftp_connection $remote
|
|
|
|
|
|
|
|
fi
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# REST Server repository
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "rest" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 04:55:37 +01:00
|
|
|
# connection test
|
|
|
|
if [ "$testconnect" = "yes" ] || [ "$test" -eq 1 ]; then
|
|
|
|
|
|
|
|
remote="${repository#rest:}"
|
|
|
|
test_rest_connection $remote
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 04:55:37 +01:00
|
|
|
fi
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Amazon S3 repository
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "s3" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 12:12:09 +02:00
|
|
|
( [ -z "$aws_access_key_id" ] || [ -z "$aws_secret_access_key" ] ) && \
|
2018-06-06 17:48:03 +02:00
|
|
|
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-08-09 11:35:49 +02:00
|
|
|
[ -n "$aws_session_token" ] && \
|
|
|
|
export_debug AWS_SESSION_TOKEN "$aws_session_token"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# OpenStack Swift repository
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "swift" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 12:12:09 +02:00
|
|
|
(
|
|
|
|
[ -z "$os_auth_url" ] || [ -z "$os_tenant_id" ] || [ -z "$os_tenant_name" ] || \
|
|
|
|
[ -z "$os_username" ] || [ -z "$os_password" ] || [ -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
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "b2" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 12:12:09 +02:00
|
|
|
( [ -z "$b2_account_id" ] || [ -z "$b2_account_key" ] ) && \
|
2018-06-06 17:48:03 +02:00
|
|
|
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
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "azure" ]; then
|
2018-06-06 17:48:03 +02:00
|
|
|
|
2018-06-07 12:12:09 +02:00
|
|
|
( [ -z "$azure_account_name" ] || [ -z "$azure_account_key" ] ) && \
|
2018-06-06 17:48:03 +02:00
|
|
|
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
|
2021-01-10 04:18:28 +01:00
|
|
|
if [ "$(echo "$repository" | @AWK@ -F ':' '{print $1}')" == "gs" ]; then
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2018-06-07 12:12:09 +02:00
|
|
|
( [ -z "$google_project_id" ] || [ -z "$google_application_credentials" ] ) && \
|
2018-06-06 17:48:03 +02:00
|
|
|
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-07 12:12:09 +02:00
|
|
|
[ -z "$include" ] && [ -z "$files_from" ] && \
|
2018-06-06 17:48:03 +02:00
|
|
|
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)"
|
|
|
|
|
2018-08-09 11:36:54 +02:00
|
|
|
[ -d "$repository" ] && \
|
2018-06-06 17:48:03 +02:00
|
|
|
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
|
2021-01-11 23:56:01 +01:00
|
|
|
cmd="restic backup"
|
|
|
|
execstr="${precmd}${cmd} ${cmd_global_options//$'\n'}${cmd_options//$'\n'}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 23:15:17 +01:00
|
|
|
# debug
|
|
|
|
debug "executing restic backup"
|
|
|
|
debug "$execstr"
|
|
|
|
|
|
|
|
# execute
|
|
|
|
if [ $test -eq 1 ]; then
|
|
|
|
info "Test mode enabled, skipping restic backup."
|
|
|
|
else
|
|
|
|
info "Creating new backup snapshot."
|
|
|
|
output=$($execstr 2>&1)
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
|
|
debug $output
|
|
|
|
info "Restic backup successful."
|
|
|
|
else
|
|
|
|
error $output
|
|
|
|
fatal "Restic backup failed."
|
|
|
|
fi
|
|
|
|
fi
|
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_options
|
2021-01-11 23:15:17 +01:00
|
|
|
unset execstr
|
|
|
|
unset output
|
|
|
|
unset ret
|
|
|
|
|
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
|
2021-01-11 23:56:01 +01:00
|
|
|
cmd="restic forget"
|
|
|
|
execstr="${precmd}${cmd} ${cmd_global_options//$'\n'}${cmd_options//$'\n'}"
|
2021-01-11 23:15:17 +01:00
|
|
|
|
|
|
|
# debug
|
|
|
|
debug "executing restic forget"
|
|
|
|
debug "$execstr"
|
2018-06-06 11:10:10 +02:00
|
|
|
|
2021-01-11 23:15:17 +01:00
|
|
|
# execute
|
|
|
|
if [ $test -eq 1 ]; then
|
|
|
|
info "Test mode enabled, skipping restic forget."
|
|
|
|
else
|
|
|
|
info "Removing old snapshots based on defined retention policy."
|
|
|
|
output=$($execstr 2>&1)
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
|
|
debug $output
|
|
|
|
info "Restic forget successful."
|
|
|
|
else
|
|
|
|
error $output
|
|
|
|
fatal "Restic forget failed."
|
|
|
|
fi
|
|
|
|
fi
|
2018-06-06 17:48:03 +02:00
|
|
|
|
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd_options
|
2021-01-11 23:15:17 +01:00
|
|
|
unset execstr
|
|
|
|
unset output
|
|
|
|
unset ret
|
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
|
2021-01-11 23:56:01 +01:00
|
|
|
cmd="restic check"
|
|
|
|
execstr="${precmd}${cmd} ${cmd_global_options//$'\n'}${cmd_options//$'\n'}"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 23:15:17 +01:00
|
|
|
# debug
|
|
|
|
debug "executing restic check"
|
|
|
|
debug "$execstr"
|
|
|
|
|
|
|
|
# execute
|
|
|
|
if [ $test -eq 1 ]; then
|
|
|
|
info "Test mode enabled, skipping restic check."
|
|
|
|
else
|
|
|
|
info "Checking repository integrity and consistency."
|
|
|
|
output=$($execstr 2>&1)
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
|
|
debug $output
|
|
|
|
info "Restic check successful."
|
|
|
|
else
|
|
|
|
error $output
|
|
|
|
fatal "Restic check failed."
|
|
|
|
fi
|
|
|
|
fi
|
2018-06-06 17:48:03 +02:00
|
|
|
|
|
|
|
debug "Unsetting variables"
|
|
|
|
unset cmd_options
|
2021-01-11 23:15:17 +01:00
|
|
|
unset execstr
|
|
|
|
unset output
|
|
|
|
unset ret
|
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
|
2021-01-11 23:56:01 +01:00
|
|
|
cmd="restic prune"
|
|
|
|
execstr="${precmd}${cmd} ${cmd_global_options//$'\n'}"
|
2021-01-11 23:15:17 +01:00
|
|
|
|
|
|
|
# debug
|
|
|
|
debug "executing restic prune"
|
|
|
|
debug "$execstr"
|
2018-06-06 09:51:21 +02:00
|
|
|
|
2021-01-11 23:15:17 +01:00
|
|
|
# execute
|
|
|
|
if [ $test -eq 1 ]; then
|
|
|
|
info "Test mode enabled, skipping restic prune."
|
|
|
|
else
|
|
|
|
info "Removing unreferenced data from repository."
|
|
|
|
output=$($execstr 2>&1)
|
|
|
|
ret=$?
|
|
|
|
if [ $ret -eq 0 ]; then
|
|
|
|
debug $output
|
|
|
|
info "Restic prune successful."
|
|
|
|
else
|
|
|
|
error $output
|
|
|
|
fatal "Restic prune failed."
|
|
|
|
fi
|
|
|
|
fi
|
2018-06-06 17:48:03 +02:00
|
|
|
|
|
|
|
debug "Unsetting variables"
|
2021-01-11 23:15:17 +01:00
|
|
|
unset execstr
|
|
|
|
unset output
|
|
|
|
unset ret
|
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
|
2018-08-09 11:39:16 +02:00
|
|
|
unset AWS_SESSION_TOKEN
|
2018-06-06 09:51:21 +02:00
|
|
|
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
|