tests: make filename optional in set/delconfig

This commit is contained in:
Jerome Charaoui 2021-01-06 00:26:09 -05:00
parent bf612c9390
commit 3733864bfb
6 changed files with 240 additions and 234 deletions

View File

@ -46,50 +46,50 @@ finish_borg() {
}
@test "check ssh connection test" {
setconfig backup.d/test.borg testconnect yes
setconfig backup.d/test.borg dest user $BN_REMOTEUSER
setconfig backup.d/test.borg dest host $BN_REMOTEHOST
setconfig testconnect yes
setconfig dest user $BN_REMOTEUSER
setconfig dest host $BN_REMOTEHOST
testaction
greplog "Debug: Connected to ${BN_REMOTEHOST} as ${BN_REMOTEUSER} successfully$"
}
@test "check config parameter nicelevel" {
# nicelevel is 0 by default
delconfig backup.d/test.borg nicelevel
delconfig nicelevel
testaction
greplog 'Debug: executing borg create$' '\bnice -n 0\b'
# nicelevel is defined
setconfig backup.d/test.borg nicelevel -19
setconfig nicelevel -19
testaction
greplog 'Debug: executing borg create$' '\bnice -n -19\b'
}
@test "check config parameter ionicelevel" {
# no ionice by default
delconfig backup.d/test.borg ionicelevel
delconfig ionicelevel
testaction
not_greplog 'Debug: executing borg create$' '\bionice -c2\b'
# acceptable value
setconfig backup.d/test.borg ionicelevel 7
setconfig ionicelevel 7
testaction
greplog 'Debug: executing borg create$' '\bionice -c2 -n 7\b'
# unacceptable value
setconfig backup.d/test.borg ionicelevel 10
setconfig ionicelevel 10
testaction
greplog 'Fatal: The value of ionicelevel is expected to be either empty or an integer from 0 to 7. Got: 10$'
}
@test "check config parameter bwlimit" {
# no limit by default
delconfig backup.d/test.borg bwlimit
delconfig bwlimit
testaction
not_greplog 'Debug: executing borg create$' '\s--remote-ratelimit='
# limit is defined
setconfig backup.d/test.borg bwlimit 1024
setconfig bwlimit 1024
testaction
greplog 'Debug: executing borg create$' '\s--remote-ratelimit=1024\b'
@ -97,140 +97,138 @@ finish_borg() {
@test "check config parameter source/init" {
# do repository init by default
delconfig backup.d/test.borg source init
delconfig source init
testaction
greplog 'Debug: executing borg init$'
# do repository init
setconfig backup.d/test.borg source init yes
setconfig source init yes
testaction
greplog 'Debug: executing borg init$'
# don't do repository init
setconfig backup.d/test.borg source init no
setconfig source init no
testaction
not_greplog 'Debug: executing borg init$'
}
@test "check config parameter source/include" {
# missing path
delconfig backup.d/test.borg source include
delconfig source include
testaction
greplog 'Fatal: No source includes specified$'
# single path
setconfig backup.d/test.borg source include "$BN_SRCDIR"
setconfig source include "$BN_SRCDIR"
testaction
greplog 'Debug: executing borg create$' "'${BN_SRCDIR}'$"
# multiple paths
setconfig_repeat backup.d/test.borg source include "$BN_SRCDIR" /foo /bar
setconfig_repeat source include "$BN_SRCDIR" /foo /bar
testaction
greplog 'Debug: executing borg create$' "'${BN_SRCDIR}' '/foo' '/bar'$"
}
@test "check config parameter source/exclude" {
# absent path
delconfig backup.d/test.borg source exclude
delconfig source exclude
testaction
not_greplog 'Debug: executing borg create$' "\s--exclude\s"
# single path
setconfig backup.d/test.borg source exclude "${BN_SRCDIR}/var"
setconfig source exclude "${BN_SRCDIR}/var"
testaction
greplog 'Debug: executing borg create$' "\s--exclude '${BN_SRCDIR}/var'\s"
# multiple paths
setconfig_repeat backup.d/test.borg source exclude "$BN_SRCDIR/var" "$BN_SRCDIR/foo" "$BN_SRCDIR/bar"
setconfig_repeat source exclude "$BN_SRCDIR/var" "$BN_SRCDIR/foo" "$BN_SRCDIR/bar"
testaction
greplog 'Debug: executing borg create$' "\s--exclude '${BN_SRCDIR}/var' --exclude '${BN_SRCDIR}/foo' --exclude '${BN_SRCDIR}/bar'\s"
}
@test "check config parameter source/create_options" {
# absent parameter
delconfig backup.d/test.borg source create_options
delconfig source create_options
testaction
not_greplog 'Debug: executing borg create$' "\s--create-options\s"
# defined parameter
setconfig backup.d/test.borg source create_options "--exclude-caches"
setconfig source create_options "--exclude-caches"
testaction
greplog 'Debug: executing borg create$' "\s--exclude-caches\b"
}
@test "check config parameter source/prune" {
# absent parameter, defaults enabled
delconfig backup.d/test.borg source prune
delconfig source prune
testaction
greplog 'Debug: executing borg prune$'
# defined parameter, enabled
setconfig backup.d/test.borg source prune yes
setconfig source prune yes
testaction
greplog 'Debug: executing borg prune$'
# defined parameter, disabled
setconfig backup.d/test.borg source prune no
cat "${BATS_TMPDIR}/backup.d/test.borg"
setconfig source prune no
testaction
not_greplog 'Debug: executing borg prune$'
}
@test "check config parameter source/keep" {
# absent parameter, defaults to '30d'
setconfig backup.d/test.borg source prune yes
delconfig backup.d/test.borg source keep
setconfig source prune yes
delconfig source keep
testaction
greplog 'Debug: executing borg prune$' '\s--keep-within=30d\b'
# defined parameter, set to 60d
setconfig backup.d/test.borg source prune yes
setconfig backup.d/test.borg source keep 60d
setconfig source prune yes
setconfig source keep 60d
testaction
greplog 'Debug: executing borg prune$' '\s--keep-within=60d\b'
# defined parameter, disabled, set to 0
setconfig backup.d/test.borg source prune yes
setconfig backup.d/test.borg source keep 0
cat "${BATS_TMPDIR}/backup.d/test.borg"
setconfig source prune yes
setconfig source keep 0
testaction
not_greplog 'Debug: executing borg prune$' '\s--keep-within='
}
@test "check config parameter source/prune_options" {
# absent parameter
delconfig backup.d/test.borg source prune_options
delconfig source prune_options
testaction
greplog 'Debug: executing borg prune$' "Debug: borg prune --keep-within=30d ${BN_BACKUPDIR}/testborg$"
# defined parameter
setconfig backup.d/test.borg source prune_options "--save-space"
setconfig source prune_options "--save-space"
testaction
greplog 'Debug: executing borg prune$' '\s--save-space\b'
}
@test "check config parameter source/cache_directory" {
# absent parameter
delconfig backup.d/test.borg source cache_directory
delconfig source cache_directory
testaction
not_greplog 'Debug: export BORG_CACHE_DIR='
# defined parameter
setconfig backup.d/test.borg source cache_directory "/var/cache/borg"
setconfig source cache_directory "/var/cache/borg"
testaction
greplog 'Debug: export BORG_CACHE_DIR="/var/cache/borg"$'
}
@test "check config parameter dest/user" {
# absent parameter
delconfig backup.d/test.borg dest user
setconfig backup.d/test.borg dest host "$BN_REMOTEHOST"
delconfig dest user
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog 'Fatal: Destination user not set$'
# defined parameter
setconfig backup.d/test.borg dest user "$BN_REMOTEUSER"
setconfig backup.d/test.borg dest host "$BN_REMOTEHOST"
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testborg::"
@ -238,14 +236,14 @@ finish_borg() {
@test "check config parameter dest/host" {
# absent parameter
delconfig backup.d/test.borg dest host
setconfig backup.d/test.borg dest user "$BN_REMOTEUSER"
delconfig dest host
setconfig dest user "$BN_REMOTEUSER"
testaction
greplog 'Fatal: Destination host not set$'
# defined parameter
setconfig backup.d/test.borg dest user "$BN_REMOTEUSER"
setconfig backup.d/test.borg dest host "$BN_REMOTEHOST"
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testborg::"
@ -253,17 +251,17 @@ finish_borg() {
@test "check config parameter dest/port" {
# absent parameter, defaults to 22
setconfig backup.d/test.borg dest user "$BN_REMOTEUSER"
setconfig backup.d/test.borg dest host "$BN_REMOTEHOST"
delconfig backup.d/test.borg dest port
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
delconfig dest port
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 22 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testborg::"
# defined parameter
setconfig backup.d/test.borg dest port 7722
setconfig backup.d/test.borg dest user "$BN_REMOTEUSER"
setconfig backup.d/test.borg dest host "$BN_REMOTEHOST"
setconfig dest port 7722
setconfig dest user "$BN_REMOTEUSER"
setconfig dest host "$BN_REMOTEHOST"
testaction
greplog "Debug: ssh -o PasswordAuthentication=no ${BN_REMOTEHOST} -p 7722 -l ${BN_REMOTEUSER} 'echo -n 1'"
greplog 'Debug: executing borg create$' "\bssh://${BN_REMOTEUSER}@${BN_REMOTEHOST}:7722${BN_BACKUPDIR}/testborg::"
@ -271,45 +269,45 @@ finish_borg() {
@test "check config parameter dest/directory" {
# absent parameter
delconfig backup.d/test.borg dest directory
delconfig dest directory
testaction
greplog 'Fatal: Destination directory not set$'
# defined parameter
setconfig backup.d/test.borg dest directory "${BN_BACKUPDIR}/testborg"
setconfig dest directory "${BN_BACKUPDIR}/testborg"
testaction
greplog 'Debug: executing borg create$' "\s${BN_BACKUPDIR}/testborg::"
}
@test "check config parameter dest/archive" {
# absent parameter, defaults to {now:%Y-%m-%dT%H:%M:%S}
delconfig backup.d/test.borg dest archive
delconfig dest archive
testaction
greplog 'Debug: executing borg create$' "\s${BN_BACKUPDIR}/testborg::{now:%Y-%m-%dT%H:%M:%S}"
# defined parameter
setconfig backup.d/test.borg dest archive foo
setconfig dest archive foo
testaction
greplog 'Debug: executing borg create$' "\s${BN_BACKUPDIR}/testborg::foo"
}
@test "check config parameter dest/compression" {
# absent parameter, defaults to lz4
delconfig backup.d/test.borg dest compression
delconfig dest compression
testaction
greplog 'Debug: executing borg create$' "\s--compression lz4\b"
# defined parameter
setconfig backup.d/test.borg dest compression auto,zstd,13
setconfig dest compression auto,zstd,13
testaction
greplog 'Debug: executing borg create$' "\s--compression auto,zstd,13\b"
}
@test "create local backup without encryption" {
# no encryption, no passphrase
setconfig backup.d/test.borg dest archive testarchive
setconfig backup.d/test.borg dest encryption none
delconfig backup.d/test.borg dest passphrase
setconfig dest archive testarchive
setconfig dest encryption none
delconfig dest passphrase
cleanup_backups local
runaction
greplog 'Debug: executing borg init$' 'Debug: borg init --encryption=none'
@ -323,9 +321,9 @@ finish_borg() {
@test "create local backup with encryption" {
# encryption enabled, wrong passphrase
setconfig backup.d/test.borg dest archive testarchive
setconfig backup.d/test.borg dest encryption repokey
setconfig backup.d/test.borg dest passphrase 123test
setconfig dest archive testarchive
setconfig dest encryption repokey
setconfig dest passphrase 123test
cleanup_backups local
runaction
greplog 'Debug: executing borg init$' 'Debug: borg init --encryption=repokey'
@ -341,11 +339,11 @@ finish_borg() {
}
@test "create remote backup with encryption" {
setconfig backup.d/test.borg dest archive testarchive
setconfig backup.d/test.borg dest encryption repokey
setconfig backup.d/test.borg dest passphrase 123test
setconfig backup.d/test.borg dest host "${BN_REMOTEHOST}"
setconfig backup.d/test.borg dest user "${BN_REMOTEUSER}"
setconfig dest archive testarchive
setconfig dest encryption repokey
setconfig dest passphrase 123test
setconfig dest host "${BN_REMOTEHOST}"
setconfig dest user "${BN_REMOTEUSER}"
cleanup_backups remote
runaction
greplog 'Debug: executing borg init$' 'Debug: borg init --encryption=repokey'

View File

@ -81,12 +81,19 @@ teardown() {
# set parameter/value in action config file
setconfig() {
if [ -z $4 ]; then
# default section
crudini --set "${BATS_TMPDIR}/$1" '' $2 "$3"
if [ -f "${BATS_TMPDIR}/$1" ]; then
local CONFIGFILE="${BATS_TMPDIR}/$1"
shift
else
local COMP=$(basename -s .bats "${BATS_TEST_FILENAME}")
local CONFIGFILE="${BATS_TMPDIR}/backup.d/test.${COMP}"
fi
if [ -n "$3" ]; then
# named section
crudini --set "${BATS_TMPDIR}/$1" $2 $3 "$4"
crudini --set "$CONFIGFILE" "$1" "$2" "$3"
else
# default section
crudini --set "$CONFIGFILE" '' "$1" "$2"
fi
}
@ -94,25 +101,38 @@ setconfig() {
# crudini doesn't support those
# (used for include and exclude parameters)
setconfig_repeat() {
conffile="${BATS_TMPDIR}/$1"
section="$2"
param="$3"
shift 3
crudini --del "$conffile" "$section" "$param"
if [ -f "${BATS_TMPDIR}/$1" ]; then
local CONFIGFILE="${BATS_TMPDIR}/$1"
shift
else
local COMP=$(basename -s .bats "${BATS_TEST_FILENAME}")
local CONFIGFILE="${BATS_TMPDIR}/backup.d/test.${COMP}"
fi
local SECTION="$1"
local PARAM="$2"
shift 2
crudini --del "$CONFIGFILE" "$SECTION" "$PARAM"
for v; do
crudini --set --list --list-sep=$'\nREPEAT = ' "$conffile" "$section" "$param" "$v"
crudini --set --list --list-sep=$'\nREPEAT = ' "$CONFIGFILE" "$SECTION" "$PARAM" "$v"
done
sed -i "s#^\s\+REPEAT =#${param} =#" "${conffile}"
sed -i "s#^\s\+REPEAT =#${PARAM} =#" "$CONFIGFILE"
}
# delete config parameter
delconfig() {
if [ -z $3 ]; then
# default section
crudini --del "${BATS_TMPDIR}/$1" '' $2
if [ -f "${BATS_TMPDIR}/$1" ]; then
local CONFIGFILE="${BATS_TMPDIR}/$1"
shift
else
local COMP=$(basename -s .bats "${BATS_TEST_FILENAME}")
local CONFIGFILE="${BATS_TMPDIR}/backup.d/test.${COMP}"
fi
if [ -n "$2" ]; then
# named section
crudini --del "${BATS_TMPDIR}/$1" $2 $3
crudini --del "$CONFIGFILE" "$1" "$2"
else
# default section
crudini --del "$CONFIGFILE" '' "$1"
fi
}

View File

@ -63,162 +63,162 @@ finish_dup() {
}
@test "check ssh connection test" {
setconfig backup.d/test.dup testconnect yes
setconfig backup.d/test.dup dest destuser $BN_REMOTEUSER
setconfig backup.d/test.dup dest desthost $BN_REMOTEHOST
delconfig backup.d/test.dup dest desturl
setconfig testconnect yes
setconfig dest destuser $BN_REMOTEUSER
setconfig dest desthost $BN_REMOTEHOST
delconfig dest desturl
testaction
greplog "Debug: Connected to ${BN_REMOTEHOST} as ${BN_REMOTEUSER} successfully$"
}
@test "check config parameter nicelevel" {
# nicelevel is 0 by default
delconfig backup.d/test.dup nicelevel
delconfig nicelevel
testaction
greplog 'Debug: executing duplicity$' '\bnice -n 0\b'
# nicelevel is defined
setconfig backup.d/test.dup nicelevel -19
setconfig nicelevel -19
testaction
greplog 'Debug: executing duplicity$' '\bnice -n -19\b'
}
@test "check config parameter ionicelevel" {
# no ionice by default
delconfig backup.d/test.dup ionicelevel
delconfig ionicelevel
testaction
not_greplog 'Debug: executing duplicity$' '\bionice -c2\b'
# acceptable value
setconfig backup.d/test.dup ionicelevel 7
setconfig ionicelevel 7
testaction
greplog 'Debug: executing duplicity$' '\bionice -c2 -n 7\b'
# unacceptable value
setconfig backup.d/test.dup ionicelevel 10
setconfig ionicelevel 10
testaction
greplog 'Fatal: The value of ionicelevel is expected to be either empty or an integer from 0 to 7. Got: 10$'
}
@test "check config parameter options" {
setconfig backup.d/test.dup options "--verbosity 8"
setconfig options "--verbosity 8"
testaction
greplog 'Debug: executing duplicity$' '\s--verbosity 8\b'
}
@test "check config parameter tmpdir" {
# tmpdir undefined
delconfig backup.d/test.dup tmpdir
delconfig tmpdir
testaction
not_greplog 'Debug: executing duplicity$' '\s--tmpdir\b'
# tmpdir defined
setconfig backup.d/test.dup tmpdir /tmp
setconfig tmpdir /tmp
testaction
not_greplog 'Debug: executing duplicity$' '\s--tmpdir /tmp\b'
}
@test "check config parameter source/include" {
# missing path
delconfig backup.d/test.dup source include
delconfig source include
testaction
greplog 'Fatal: No source includes specified.$'
# single path
setconfig backup.d/test.dup source include "$BN_SRCDIR"
setconfig source include "$BN_SRCDIR"
testaction
greplog 'Debug: executing duplicity$' "\s--include '${BN_SRCDIR}'"
# multiple paths
setconfig_repeat backup.d/test.dup source include "$BN_SRCDIR" /foo /bar
setconfig_repeat source include "$BN_SRCDIR" /foo /bar
testaction
greplog 'Debug: executing duplicity$' "\s--include '${BN_SRCDIR}' --include '/foo' --include '/bar'\s"
}
@test "check config parameter source/exclude" {
# absent path
delconfig backup.d/test.dup source exclude
delconfig source exclude
testaction
greplog 'Debug: executing duplicity$' "\s--include '${BN_SRCDIR}' --exclude '\*\*' /\s"
# single path
setconfig backup.d/test.dup source exclude "${BN_SRCDIR}/var"
setconfig source exclude "${BN_SRCDIR}/var"
testaction
greplog 'Debug: executing duplicity$' "\s--exclude '${BN_SRCDIR}/var'\s"
# multiple paths
setconfig_repeat backup.d/test.dup source exclude "$BN_SRCDIR/var" "$BN_SRCDIR/foo" "$BN_SRCDIR/bar"
setconfig_repeat source exclude "$BN_SRCDIR/var" "$BN_SRCDIR/foo" "$BN_SRCDIR/bar"
testaction
greplog 'Debug: executing duplicity$' "\s--exclude '${BN_SRCDIR}/var' --exclude '${BN_SRCDIR}/foo' --exclude '${BN_SRCDIR}/bar'\s"
}
@test "check config parameter dest/incremental" {
# absent parameter, defaults to yes
delconfig backup.d/test.dup dest incremental
delconfig dest incremental
testaction
greplog 'Debug: executing duplicity$' 'Debug: nice -n 0 LC_ALL=C duplicity --no-print-statistics'
# defined, set to yes
setconfig backup.d/test.dup dest incremental yes
setconfig dest incremental yes
testaction
greplog 'Debug: executing duplicity$' 'Debug: nice -n 0 LC_ALL=C duplicity --no-print-statistics'
# defined, set to no
setconfig backup.d/test.dup dest incremental no
setconfig dest incremental no
testaction
greplog 'Debug: executing duplicity$' 'Debug: nice -n 0 LC_ALL=C duplicity full --no-print-statistics'
}
@test "check config parameter dest/increments" {
# absent parameter, defaults to 30
delconfig backup.d/test.dup dest increments
delconfig dest increments
testaction
greplog 'Debug: executing duplicity$' '\s--full-if-older-than 30D\b'
# defined, set to 60
setconfig backup.d/test.dup dest increments 60
setconfig dest increments 60
testaction
greplog 'Debug: executing duplicity$' '\s--full-if-older-than 60D\b'
# defined, set to keep
setconfig backup.d/test.dup dest increments keep
setconfig dest increments keep
testaction
not_greplog 'Debug: executing duplicity$' '\s--full-if-older-than\s'
}
@test "check config parameter dest/keep" {
# absent parameter, defaults to 60
delconfig backup.d/test.dup dest keep
delconfig dest keep
testaction
greplog 'Debug: executing duplicity remove-older-than$' '\sduplicity remove-older-than 60D\b'
# defined, set to 180
setconfig backup.d/test.dup dest keep 180
setconfig dest keep 180
testaction
greplog 'Debug: executing duplicity remove-older-than$' '\sduplicity remove-older-than 180D\b'
# defined, set to yes
setconfig backup.d/test.dup dest keep yes
setconfig dest keep yes
testaction
not_greplog 'Debug: executing duplicity remove-older-than$'
}
@test "check config parameter dest/keepincroffulls" {
# absent parameter, defaults to all
setconfig backup.d/test.dup dest keep 30
delconfig backup.d/test.dup dest keepincroffulls
setconfig dest keep 30
delconfig dest keepincroffulls
testaction
not_greplog 'Debug: executing duplicity remove-all-inc-of-but-n-full$'
# defined, set to 1
setconfig backup.d/test.dup dest keep 30
setconfig backup.d/test.dup dest keepincroffulls 1
setconfig dest keep 30
setconfig dest keepincroffulls 1
testaction
greplog 'Debug: executing duplicity remove-all-inc-of-but-n-full$' '\sduplicity remove-all-inc-of-but-n-full 1\b'
# defined, set to all
setconfig backup.d/test.dup dest keep 30
setconfig backup.d/test.dup dest keepincroffulls all
setconfig dest keep 30
setconfig dest keepincroffulls all
testaction
not_greplog 'Debug: executing duplicity remove-all-inc-of-but-n-full$'
}
@ -261,59 +261,59 @@ finish_dup() {
@test "check config parameter dest/sshoptions" {
# undefined
delconfig backup.d/test.dup dest sshoptions
delconfig dest sshoptions
testaction
greplog 'Debug: executing duplicity$' "\s--ssh-options ''\s"
# defined
setconfig backup.d/test.dup dest sshoptions "-oIdentityFile=/root/.ssh/id_rsa"
setconfig dest sshoptions "-oIdentityFile=/root/.ssh/id_rsa"
testaction
greplog 'Debug: executing duplicity$' "\s--ssh-options '-oIdentityFile=/root/.ssh/id_rsa'\s"
}
@test "check config parameter dest/bandwidthlimit" {
# undefined, disabled by default
delconfig backup.d/test.dup dest bandwidthlimit
delconfig dest bandwidthlimit
testaction
not_greplog "\btrickle -s\b"
# defined, set to 250, local file path
setconfig backup.d/test.dup dest bandwidthlimit 250
setconfig backup.d/test.dup dest desturl "file://${BN_BACKUPDIR}/testdup"
setconfig dest bandwidthlimit 250
setconfig dest desturl "file://${BN_BACKUPDIR}/testdup"
testaction
greplog 'Warning: The bandwidthlimit option is not used with a local file path destination.'
not_greplog 'Debug: executing duplicity$' "\strickle -s -d 250 -u 250 duplicity\s"
# defined, set to 250, remote path
setconfig backup.d/test.dup dest bandwidthlimit 250
setconfig backup.d/test.dup dest desturl "sftp://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testdup"
setconfig dest bandwidthlimit 250
setconfig dest desturl "sftp://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testdup"
testaction
greplog 'Debug: executing duplicity$' "\strickle -s -d 250 -u 250 duplicity\s"
}
@test "check config parameter dest/desturl" {
# undefined desturl
delconfig backup.d/test.dup dest desturl
delconfig backup.d/test.dup dest desthost
delconfig dest desturl
delconfig dest desthost
testaction
greplog 'Fatal: The destination host (desthost) must be set when desturl is not used.$'
# desturl, file protocol
setconfig backup.d/test.dup dest desturl "file://${BN_BACKUPDIR}/testdup"
setconfig dest desturl "file://${BN_BACKUPDIR}/testdup"
testaction
greplog 'Debug: executing duplicity$' "\sfile://${BN_BACKUPDIR}/testdup$"
# desturl, sftp protocol
setconfig backup.d/test.dup dest desturl "sftp://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testdup"
setconfig dest desturl "sftp://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testdup"
testaction
greplog 'Debug: executing duplicity$' "\ssftp://${BN_REMOTEUSER}@${BN_REMOTEHOST}:22${BN_BACKUPDIR}/testdup$"
}
@test "check config parameters dest/desthost, dest/destuser, dest/destdir" {
delconfig backup.d/test.dup dest desturl
setconfig backup.d/test.dup dest desthost "$BN_REMOTEHOST"
setconfig backup.d/test.dup dest destuser "$BN_REMOTEUSER"
setconfig backup.d/test.dup dest destdir "$BN_BACKUPDIR/testdup"
delconfig dest desturl
setconfig dest desthost "$BN_REMOTEHOST"
setconfig dest destuser "$BN_REMOTEUSER"
setconfig dest destdir "$BN_BACKUPDIR/testdup"
testaction
greplog 'Debug: executing duplicity$' "\sscp://${BN_REMOTEUSER}@${BN_REMOTEHOST}/${BN_BACKUPDIR}/testdup$"
}
@ -321,9 +321,9 @@ finish_dup() {
@test "create local backup with symmetric encryption" {
cleanup_backups local
mkdir -p /var/backups/testdup
setconfig backup.d/test.dup gpg password 123test
setconfig backup.d/test.dup dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig backup.d/test.dup dest destdir
setconfig gpg password 123test
setconfig dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig dest destdir
runaction
greplog "Debug: Data will be encrypted using symmetric encryption."
greplog "Info: Duplicity finished successfully."
@ -341,10 +341,10 @@ finish_dup() {
makegpgkeys
cleanup_backups local
mkdir -p /var/backups/testdup
setconfig backup.d/test.dup gpg encryptkey "$BN_ENCRYPTKEY"
setconfig backup.d/test.dup gpg password 123test
setconfig backup.d/test.dup dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig backup.d/test.dup dest destdir
setconfig gpg encryptkey "$BN_ENCRYPTKEY"
setconfig gpg password 123test
setconfig dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig dest destdir
runaction
greplog "Debug: Data will be encrypted with the GnuPG key $BN_ENCRYPTKEY.$"
greplog "Debug: Data won't be signed."
@ -364,11 +364,11 @@ finish_dup() {
makegpgkeys
cleanup_backups local
mkdir -p /var/backups/testdup
setconfig backup.d/test.dup gpg encryptkey "$BN_ENCRYPTKEY"
setconfig backup.d/test.dup gpg password 123encrypt
setconfig backup.d/test.dup gpg sign yes
setconfig backup.d/test.dup dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig backup.d/test.dup dest destdir
setconfig gpg encryptkey "$BN_ENCRYPTKEY"
setconfig gpg password 123encrypt
setconfig gpg sign yes
setconfig dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig dest destdir
runaction
greplog "Debug: Data will be encrypted ang signed with the GnuPG key ${BN_ENCRYPTKEY}.$"
greplog "Info: Duplicity finished successfully."
@ -387,13 +387,13 @@ finish_dup() {
makegpgkeys
cleanup_backups local
mkdir -p /var/backups/testdup
setconfig backup.d/test.dup gpg encryptkey "$BN_ENCRYPTKEY"
setconfig backup.d/test.dup gpg password 123encrypt
setconfig backup.d/test.dup gpg sign yes
setconfig backup.d/test.dup gpg signkey "$BN_SIGNKEY"
setconfig backup.d/test.dup gpg signpassword 123sign
setconfig backup.d/test.dup dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig backup.d/test.dup dest destdir
setconfig gpg encryptkey "$BN_ENCRYPTKEY"
setconfig gpg password 123encrypt
setconfig gpg sign yes
setconfig gpg signkey "$BN_SIGNKEY"
setconfig gpg signpassword 123sign
setconfig dest desturl "file://${BN_BACKUPDIR}/testdup"
delconfig dest destdir
runaction
greplog "Debug: Data will be encrypted with the GnuPG key ${BN_ENCRYPTKEY}.$"
greplog "Debug: Data will be signed with the GnuPG key ${BN_SIGNKEY}.$"
@ -410,11 +410,11 @@ finish_dup() {
}
@test "create remote backup with symmetric encryption" {
setconfig backup.d/test.dup gpg password 123test
delconfig backup.d/test.dup dest desturl
setconfig backup.d/test.dup dest destuser "$BN_REMOTEUSER"
setconfig backup.d/test.dup dest desthost "$BN_REMOTEHOST"
setconfig backup.d/test.dup dest destdir "${BN_BACKUPDIR}/testdup"
setconfig gpg password 123test
delconfig dest desturl
setconfig dest destuser "$BN_REMOTEUSER"
setconfig dest desthost "$BN_REMOTEHOST"
setconfig dest destdir "${BN_BACKUPDIR}/testdup"
cleanup_backups remote
runaction
greplog "Debug: Data will be encrypted using symmetric encryption."
@ -431,13 +431,13 @@ finish_dup() {
@test "create remote backup with public key encryption, signed with same key" {
makegpgkeys
setconfig backup.d/test.dup gpg encryptkey "$BN_ENCRYPTKEY"
setconfig backup.d/test.dup gpg password 123encrypt
setconfig backup.d/test.dup gpg sign yes
delconfig backup.d/test.dup dest desturl
setconfig backup.d/test.dup dest destuser "$BN_REMOTEUSER"
setconfig backup.d/test.dup dest desthost "$BN_REMOTEHOST"
setconfig backup.d/test.dup dest destdir "${BN_BACKUPDIR}/testdup"
setconfig gpg encryptkey "$BN_ENCRYPTKEY"
setconfig gpg password 123encrypt
setconfig gpg sign yes
delconfig dest desturl
setconfig dest destuser "$BN_REMOTEUSER"
setconfig dest desthost "$BN_REMOTEHOST"
setconfig dest destdir "${BN_BACKUPDIR}/testdup"
cleanup_backups remote
runaction
greplog "Debug: Data will be encrypted ang signed with the GnuPG key ${BN_ENCRYPTKEY}.$"

View File

@ -30,8 +30,8 @@ teardown_mysql() {
}
@test "sqldump: exports all databases, with compression" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql compress yes
setconfig databases all
setconfig compress yes
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz" ]
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_v11vJj.sql.gz" ]
@ -40,8 +40,8 @@ teardown_mysql() {
}
@test "sqldump: exports all databases, without compression" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql compress no
setconfig databases all
setconfig compress no
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql" ]
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_v11vJj.sql" ]
@ -50,7 +50,7 @@ teardown_mysql() {
}
@test "sqldump: exports specific database" {
setconfig backup.d/test.mysql databases bntest_v11vJj
setconfig databases bntest_v11vJj
runaction
[ ! -f ${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz ]
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_v11vJj.sql.gz" ]
@ -58,8 +58,8 @@ teardown_mysql() {
}
@test "ignores: exports all databases while excluding two tables entirely" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql ignores "bntest_v11vJj.cache_data bntest_v11vJj.cache_entity"
setconfig databases all
setconfig ignores "bntest_v11vJj.cache_data bntest_v11vJj.cache_entity"
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz" ]
[ "$(zgrep -c 'INSERT INTO' ${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz)" -eq 9 ]
@ -70,9 +70,9 @@ teardown_mysql() {
}
@test "nodata: exports all databases while excluding data from one table, with compression" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql compress yes
setconfig backup.d/test.mysql nodata bntest_v11vJj.cache_data
setconfig databases all
setconfig compress yes
setconfig nodata bntest_v11vJj.cache_data
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz" ]
[ "$(zgrep -c 'INSERT INTO' ${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz)" -eq 9 ]
@ -82,9 +82,9 @@ teardown_mysql() {
}
@test "nodata: exports all databases while excluding data from one table, without compression" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql compress no
setconfig backup.d/test.mysql nodata bntest_v11vJj.cache_data
setconfig databases all
setconfig compress no
setconfig nodata bntest_v11vJj.cache_data
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql" ]
[ "$(grep -c 'INSERT INTO' ${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql)" -eq 9 ]
@ -94,9 +94,9 @@ teardown_mysql() {
}
@test "nodata: exports all databases while excluding data from two tables, with compression" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql compress yes
setconfig backup.d/test.mysql nodata "bntest_v11vJj.cache_data bntest_v11vJj.cache_entity"
setconfig databases all
setconfig compress yes
setconfig nodata "bntest_v11vJj.cache_data bntest_v11vJj.cache_entity"
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz" ]
[ "$(zgrep -c 'INSERT INTO' ${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql.gz)" -eq 9 ]
@ -107,9 +107,9 @@ teardown_mysql() {
}
@test "nodata: exports all databases while excluding data from two tables, without compression" {
setconfig backup.d/test.mysql databases all
setconfig backup.d/test.mysql compress no
setconfig backup.d/test.mysql nodata "bntest_v11vJj.cache_data bntest_v11vJj.cache_entity"
setconfig databases all
setconfig compress no
setconfig nodata "bntest_v11vJj.cache_data bntest_v11vJj.cache_entity"
runaction
[ -s "${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql" ]
[ "$(grep -c 'INSERT INTO' ${BN_BACKUPDIR}/mysql/sqldump/bntest_p8Cz8k.sql)" -eq 9 ]

View File

@ -33,62 +33,56 @@ teardown_pgsql() {
}
@test "plain: exports all databases, with compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format plain
setconfig databases all
setconfig compress yes
setconfig format plain
runaction
[ "$status" -eq 0 ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest0-all.sql.gz"
}
@test "plain: exports all databases, without compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format plain
setconfig databases all
setconfig compress no
setconfig format plain
runaction
[ "$status" -eq 0 ]
[ -s "${BN_BACKUPDIR}/postgres/bntest0-all.sql" ]
}
@test "plain: exports specific database, with compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format plain
setconfig databases bntest_v11vJj
setconfig compress yes
setconfig format plain
runaction
[ "$status" -eq 0 ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql.gz"
[ "$(zgrep -c -e '^COPY' ${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql.gz)" -eq 68 ]
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.sql.gz" ]
}
@test "plain: exports specific database, without compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format plain
setconfig databases bntest_v11vJj
setconfig compress no
setconfig format plain
runaction
[ "$status" -eq 0 ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql" ]
[ "$(grep -c -e '^COPY' ${BN_BACKUPDIR}/postgres/bntest_v11vJj.sql)" -eq 68 ]
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.sql" ]
}
@test "tar: exports all databases, with compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format tar
setconfig databases all
setconfig compress yes
setconfig format tar
runaction
[ "$status" -eq 0 ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/globals.sql.gz"
}
@test "tar: exports all databases, without compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format tar
setconfig databases all
setconfig compress no
setconfig format tar
runaction
[ "$status" -eq 0 ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file ${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump | grep "POSIX tar archive"
@ -97,22 +91,20 @@ teardown_pgsql() {
}
@test "tar: exports specific database, with compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format tar
setconfig databases bntest_v11vJj
setconfig compress yes
setconfig format tar
runaction
[ "$status" -eq 0 ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz" ]
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql.gz" ]
}
@test "tar: exports specific database, without compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format tar
setconfig databases bntest_v11vJj
setconfig compress no
setconfig format tar
runaction
[ "$status" -eq 0 ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file ${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump | grep -q "POSIX tar archive"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
@ -120,22 +112,20 @@ teardown_pgsql() {
}
@test "custom: exports all databases, with compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format custom
setconfig databases all
setconfig compress yes
setconfig format custom
runaction
[ "$status" -eq 0 ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
gzip -tq "${BN_BACKUPDIR}/postgres/globals.sql.gz"
}
@test "custom: exports all databases, without compression" {
setconfig backup.d/test.pgsql databases all
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format custom
setconfig databases all
setconfig compress no
setconfig format custom
runaction
[ "$status" -eq 0 ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" | grep -q "PostgreSQL custom database dump"
@ -144,22 +134,20 @@ teardown_pgsql() {
}
@test "custom: exports specific database, with compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress yes
setconfig backup.d/test.pgsql format custom
setconfig databases bntest_v11vJj
setconfig compress yes
setconfig format custom
runaction
[ "$status" -eq 0 ]
gzip -tq "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump.gz"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump.gz" ]
[ ! -e "${BN_BACKUPDIR}/postgres/globals.sql.gz" ]
}
@test "custom: exports specific database, without compression" {
setconfig backup.d/test.pgsql databases bntest_v11vJj
setconfig backup.d/test.pgsql compress no
setconfig backup.d/test.pgsql format custom
setconfig databases bntest_v11vJj
setconfig compress no
setconfig format custom
runaction
[ "$status" -eq 0 ]
[ -s "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" ]
file "${BN_BACKUPDIR}/postgres/bntest_v11vJj.pg_dump" | grep -q "PostgreSQL custom database dump"
[ ! -e "${BN_BACKUPDIR}/postgres/bntest_p8Cz8k.pg_dump" ]

View File

@ -34,7 +34,7 @@ teardown_tar() {
}
@test "compress compression" {
setconfig backup.d/test.tar compress compress
setconfig compress compress
runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.compress)
@ -43,7 +43,7 @@ teardown_tar() {
}
@test "gzip compression" {
setconfig backup.d/test.tar compress gzip
setconfig compress gzip
runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tgz)
@ -52,7 +52,7 @@ teardown_tar() {
}
@test "bzip2 compression" {
setconfig backup.d/test.tar compress bzip
setconfig compress bzip
runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.bz2)
@ -61,7 +61,7 @@ teardown_tar() {
}
@test "xz compression" {
setconfig backup.d/test.tar compress xz
setconfig compress xz
runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.xz)
@ -70,7 +70,7 @@ teardown_tar() {
}
@test "zstd compression" {
setconfig backup.d/test.tar compress zstd
setconfig compress zstd
runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tar.zst)
@ -79,7 +79,7 @@ teardown_tar() {
}
@test "unknown compression, defaults to gzip" {
setconfig backup.d/test.tar compress foo
setconfig compress foo
runaction
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 1 warning." "${BATS_TMPDIR}/log/backupninja.log"
archive=$(find /var/backups/tartest -maxdepth 1 -name bntest-\*.tgz)