mirror of
https://0xacab.org/liberate/backupninja.git
synced 2024-11-08 11:52:32 +01:00
restic: init repository if needed, by default
Add backup/init config directive (defaults to yes) to control whether the repository should be initialized if it doesn't exist. Since we need to attempt to connect to the repository to verify if init is needed, remove the testconnect parameter so that the handler just tests the connection every time it runs.
This commit is contained in:
parent
36638fa6ed
commit
b013dc759b
@ -86,12 +86,6 @@ password = secret
|
||||
## Default:
|
||||
# ionicelevel =
|
||||
|
||||
## Check if remote host is alive before attempting backup. Supports SFTP and REST
|
||||
## backends at the moment. Set to no to skip this test. [yes/no]
|
||||
##
|
||||
## Default:
|
||||
# testconnect = yes
|
||||
|
||||
[s3]
|
||||
|
||||
#aws_access_key_id =
|
||||
@ -134,6 +128,9 @@ password = secret
|
||||
|
||||
[backup]
|
||||
|
||||
# Initialize the repository if it doesn't exist [yes/no]
|
||||
#init = yes
|
||||
|
||||
# Files adn directories to backup (can be specified multiple times) [path]
|
||||
#include = /
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
setsection general
|
||||
|
||||
getconf testconnect yes
|
||||
getconf nicelevel
|
||||
getconf ionicelevel
|
||||
|
||||
@ -205,24 +204,52 @@ fi
|
||||
|
||||
### TEST #######################################################################
|
||||
|
||||
if [ "$testconnect" = "yes" ] || [ "$test" -eq 1 ]; then
|
||||
info "Attempting to connect to repository at ${repository}"
|
||||
|
||||
info "Attempting to connect to repository at ${repository}"
|
||||
cmd="restic snapshots"
|
||||
execstr="${cmd} ${cmd_global_options//$'\n'}"
|
||||
|
||||
cmd="restic snapshots"
|
||||
debug "executing restic snapshots"
|
||||
debug "$execstr"
|
||||
output=$($execstr 2>&1)
|
||||
ret=$?
|
||||
|
||||
if [ $ret -eq 0 ]; then
|
||||
debug $output
|
||||
info "Connected successfully."
|
||||
else
|
||||
setsection backup
|
||||
getconf init yes
|
||||
if [ "$init" = "yes" ]; then
|
||||
debug $output
|
||||
info "Unable to find a repository at ${repository}, will attempt to create one."
|
||||
need_init="yes"
|
||||
else
|
||||
error $output
|
||||
fatal "The specified repository is absent or unusable!"
|
||||
fi
|
||||
fi
|
||||
|
||||
### INIT #######################################################################
|
||||
|
||||
if [ "$need_init" = "yes" ]; then
|
||||
|
||||
info "Initializing repository at $repository"
|
||||
|
||||
cmd="restic init"
|
||||
execstr="${cmd} ${cmd_global_options//$'\n'}"
|
||||
|
||||
debug "executing restic snapshots"
|
||||
debug "executing restic init"
|
||||
debug "$execstr"
|
||||
output=$($execstr 2>&1)
|
||||
ret=$?
|
||||
|
||||
if [ $ret -eq 0 ]; then
|
||||
debug $output
|
||||
info "Connected successfully."
|
||||
warning $output
|
||||
warning "Repository has been initialized."
|
||||
else
|
||||
error $output
|
||||
fatal "The specified repository is absent or unusable!"
|
||||
fatal "Unable to initialize repository, aborting!"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user