mirror of
https://0xacab.org/liberate/backupninja.git
synced 2024-11-09 12:22:40 +01:00
tests: overhaul rdiff handler tests
This commit is contained in:
parent
5bcaea00b8
commit
10ed1b575f
414
test/rdiff.bats
414
test/rdiff.bats
@ -10,27 +10,27 @@ begin_rdiff() {
|
||||
setup_rdiff() {
|
||||
cat << EOF > "${BATS_TMPDIR}/backup.d/test.rdiff"
|
||||
when = manual
|
||||
options = --no-carbonfile
|
||||
nicelevel = 19
|
||||
options =
|
||||
nicelevel =
|
||||
testconnect = no
|
||||
bwlimit =
|
||||
ignore_version = no
|
||||
output_as_info = yes
|
||||
ignore_version =
|
||||
output_as_info =
|
||||
keep = yes
|
||||
|
||||
[source]
|
||||
label = rdifftest
|
||||
label = testrdiff
|
||||
type = local
|
||||
keep = yes
|
||||
include = /var/cache/bntest
|
||||
exclude = /var/cache/bntest/var
|
||||
include = ${BN_SRCDIR}
|
||||
exclude = ${BN_SRCDIR}/var
|
||||
|
||||
[dest]
|
||||
type = local
|
||||
directory = /var/backups
|
||||
directory = $BN_BACKUPDIR
|
||||
host =
|
||||
user =
|
||||
sshoptions = -4
|
||||
sshoptions =
|
||||
EOF
|
||||
|
||||
chmod 0640 "${BATS_TMPDIR}/backup.d/test.rdiff"
|
||||
@ -40,51 +40,389 @@ finish_rdiff() {
|
||||
cleanup_backups local remote
|
||||
}
|
||||
|
||||
@test "local source/dest backup action runs without errors" {
|
||||
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.rdiff"
|
||||
[ "$status" -eq 0 ]
|
||||
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
|
||||
@test "check ssh connection test" {
|
||||
setconfig testconnect yes
|
||||
setconfig dest type remote
|
||||
setconfig dest user $BN_REMOTEUSER
|
||||
setconfig dest host $BN_REMOTEHOST
|
||||
testaction
|
||||
greplog "Debug: Connected to ${BN_REMOTEHOST} as ${BN_REMOTEUSER} successfully$"
|
||||
}
|
||||
|
||||
@test "local source/dest backup exists" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter nicelevel" {
|
||||
# nicelevel is 0 by default
|
||||
delconfig nicelevel
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' '\bnice -n 0\b'
|
||||
|
||||
# nicelevel is defined
|
||||
setconfig nicelevel 19
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' '\bnice -n 19\b'
|
||||
}
|
||||
|
||||
@test "local source/dest rdiff-backup options as expected" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter ionicelevel" {
|
||||
# no ionice by default
|
||||
delconfig ionicelevel
|
||||
testaction
|
||||
not_greplog 'Debug: executing rdiff-backup$' '\bionice -c2\b'
|
||||
|
||||
# acceptable value
|
||||
setconfig ionicelevel 7
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' '\bionice -c2 -n 7\b'
|
||||
|
||||
# unacceptable value
|
||||
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 "local source/dest backup ingests update" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter bwlimit" {
|
||||
# no limit by default
|
||||
delconfig bwlimit
|
||||
setconfig dest type remote
|
||||
setconfig dest user $BN_REMOTEUSER
|
||||
setconfig dest host $BN_REMOTEHOST
|
||||
testaction
|
||||
not_greplog 'Debug: executing rdiff-backup$' '\bcstream -t\b'
|
||||
|
||||
# limit is defined
|
||||
setconfig bwlimit 1024000
|
||||
setconfig dest type remote
|
||||
setconfig dest user $BN_REMOTEUSER
|
||||
setconfig dest host $BN_REMOTEHOST
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' '\bcstream -t 1024000\b'
|
||||
}
|
||||
|
||||
@test "local source/dest backup appears valid" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter ignore_version" {
|
||||
# undefined, defaults to no
|
||||
delconfig ignore_version
|
||||
setconfig dest type remote
|
||||
setconfig dest user $BN_REMOTEUSER
|
||||
setconfig dest host $BN_REMOTEHOST
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup version checks$'
|
||||
greplog 'Debug: source version: rdiff-backup '
|
||||
greplog 'Debug: destination version: rdiff-backup '
|
||||
not_greplog 'Fatal: rdiff-backup does not have the same version at the source and at the destination.$'
|
||||
|
||||
# defined, set to no
|
||||
setconfig ignore_version no
|
||||
setconfig dest type remote
|
||||
setconfig dest user $BN_REMOTEUSER
|
||||
setconfig dest host $BN_REMOTEHOST
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup version checks$'
|
||||
greplog 'Debug: source version: rdiff-backup '
|
||||
greplog 'Debug: destination version: rdiff-backup '
|
||||
not_greplog 'Fatal: rdiff-backup does not have the same version at the source and at the destination.$'
|
||||
|
||||
# defined, set to yes
|
||||
setconfig ignore_version yes
|
||||
setconfig dest type remote
|
||||
setconfig dest user $BN_REMOTEUSER
|
||||
setconfig dest host $BN_REMOTEHOST
|
||||
testaction
|
||||
not_greplog 'Debug: executing rdiff-backup version checks$'
|
||||
not_greplog 'Debug: source version: rdiff-backup '
|
||||
not_greplog 'Debug: destination version: rdiff-backup '
|
||||
not_greplog 'Fatal: rdiff-backup does not have the same version at the source and at the destination.$'
|
||||
}
|
||||
|
||||
@test "remote dest backup action runs without errors" {
|
||||
setconfig backup.d/test.rdiff testconnect yes
|
||||
setconfig backup.d/test.rdiff bwlimit 1250000
|
||||
setconfig backup.d/test.rdiff dest type remote
|
||||
setconfig backup.d/test.rdiff dest host bntest1
|
||||
setconfig backup.d/test.rdiff dest user vagrant
|
||||
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.rdiff"
|
||||
[ "$status" -eq 0 ]
|
||||
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
|
||||
@test "check config parameter options" {
|
||||
# undefined, default empty
|
||||
delconfig options
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\brdiff-backup\s\+--print-statistics\s"
|
||||
|
||||
# defined, set to --tempdir /tmp
|
||||
setconfig options "--tempdir /tmp"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\brdiff-backup\s\+--tempdir /tmp --print-statistics\s"
|
||||
}
|
||||
|
||||
@test "remote dest backup exists" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter source/type" {
|
||||
# undefined, defaults empty
|
||||
delconfig source type
|
||||
testaction
|
||||
greplog "Fatal: sourcetype '' is neither local nor remote$"
|
||||
|
||||
# defined, set to local
|
||||
setconfig source type local
|
||||
testaction
|
||||
not_greplog "Fatal: sourcetype '' is neither local nor remote$"
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, set to remote
|
||||
setconfig source type remote
|
||||
setconfig source user "$BN_REMOTEUSER"
|
||||
setconfig source host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
not_greplog "Fatal: sourcetype '' is neither local nor remote$"
|
||||
greplog 'Debug: executing rdiff-backup$' "\s${BN_REMOTEUSER}@${BN_REMOTEHOST}::/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
}
|
||||
|
||||
@test "remote dest rdiff-backup options as expected" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter source/label" {
|
||||
# undefined, defaults empty
|
||||
delconfig source label
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/$"
|
||||
|
||||
# defined, set to testrdiff
|
||||
setconfig source label testrdiff
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
}
|
||||
|
||||
@test "remote dest backup ingests update" {
|
||||
skip "not implemented"
|
||||
@test "check config parameters and source/user and source/host" {
|
||||
# user undefined, type remote, defaults empty
|
||||
setconfig source type remote
|
||||
delconfig source user
|
||||
setconfig source host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Fatal: User must be specified for remote source.'
|
||||
|
||||
# host undefined, type remote, defaults empty
|
||||
setconfig source type remote
|
||||
setconfig source user "$BN_REMOTEUSER"
|
||||
delconfig source host
|
||||
testaction
|
||||
greplog 'Fatal: Host must be specified for remote source.'
|
||||
|
||||
# user/host undefined, type local, defaults empty (noop)
|
||||
setconfig source type local
|
||||
delconfig source user
|
||||
delconfig source host
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, type remote
|
||||
setconfig source type remote
|
||||
setconfig source user "$BN_REMOTEUSER"
|
||||
setconfig source host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s${BN_REMOTEUSER}@${BN_REMOTEHOST}::/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, type local (noop)
|
||||
setconfig source type local
|
||||
setconfig source user "$BN_REMOTEUSER"
|
||||
setconfig source host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
}
|
||||
|
||||
@test "remote dest backup appears valid" {
|
||||
skip "not implemented"
|
||||
@test "check config parameter source/keep" {
|
||||
# undefined, defaults to 60
|
||||
delconfig source keep
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup --remove-older-than$' '\s--remove-older-than 60D\s'
|
||||
|
||||
# defined, set to 180
|
||||
testaction
|
||||
setconfig source keep 180
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup --remove-older-than$' '\s--remove-older-than 180D\s'
|
||||
|
||||
# defined, set to 6M
|
||||
testaction
|
||||
setconfig source keep 6M
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup --remove-older-than$' '\s--remove-older-than 6M\s'
|
||||
|
||||
# defined, set to 1 year
|
||||
testaction
|
||||
setconfig source keep "1 year"
|
||||
testaction
|
||||
greplog 'Fatal: Keep parameter contains an invalid value (1 year).$'
|
||||
|
||||
# defined, set to yes
|
||||
testaction
|
||||
setconfig source keep yes
|
||||
testaction
|
||||
not_greplog 'Fatal: Keep parameter contains an invalid value (yes).$'
|
||||
not_greplog 'Debug: executing rdiff-backup --remove-older-than$'
|
||||
}
|
||||
|
||||
@test "check config parameter source/include" {
|
||||
# no includes, defaults source path to "/"
|
||||
delconfig source include
|
||||
delconfig source exclude
|
||||
testaction
|
||||
not_greplog 'Debug: executing rdiff-backup$' "\s--include"
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--print-statistics / ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# single path, invalid
|
||||
setconfig source include /
|
||||
testaction
|
||||
greplog "Fatal: Sorry, you cannot use 'include = /'$"
|
||||
|
||||
# single path
|
||||
setconfig source include "$BN_SRCDIR"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--include '${BN_SRCDIR}' --exclude '/\*' /\s"
|
||||
|
||||
# multiple paths
|
||||
setconfig_repeat backup.d/test.rdiff source include "$BN_SRCDIR" /foo /bar
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--include '${BN_SRCDIR}' --include '/foo' --include '/bar' --exclude '/\*' /\s"
|
||||
|
||||
# regular path and filelist
|
||||
setconfig_repeat backup.d/test.rdiff source include "$BN_SRCDIR" "@/etc/backup-list.txt"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--include '${BN_SRCDIR}' --include-globbing-filelist '/etc/backup-list.txt' --exclude '/\*' /\s"
|
||||
}
|
||||
|
||||
@test "check config parameter source/exclude" {
|
||||
# no excludes, defaults source path to "/"
|
||||
delconfig source exclude
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--print-statistics --include '${BN_SRCDIR}' --exclude '/\*' / ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# single path
|
||||
setconfig source exclude "${BN_SRCDIR}/foo"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--exclude '${BN_SRCDIR}/foo' --include '${BN_SRCDIR}' --exclude '/\*' /\s"
|
||||
|
||||
# multiple paths
|
||||
setconfig_repeat backup.d/test.rdiff source exclude "${BN_SRCDIR}/foo" "${BN_SRCDIR}/bar"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--exclude '${BN_SRCDIR}/foo' --exclude '${BN_SRCDIR}/bar' --include '${BN_SRCDIR}' --exclude '/\*' /\s"
|
||||
|
||||
# regular path and filelist
|
||||
setconfig_repeat backup.d/test.rdiff source exclude "${BN_SRCDIR}/foo" "@/etc/backup-exlist.txt"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s--exclude '${BN_SRCDIR}/foo' --exclude-globbing-filelist '/etc/backup-exlist.txt' --include '${BN_SRCDIR}' --exclude '/\*' /\s"
|
||||
}
|
||||
|
||||
@test "check config parameter dest/type" {
|
||||
# undefined, defaults empty
|
||||
delconfig dest type
|
||||
testaction
|
||||
greplog "Fatal: desttype '' is neither local nor remote$"
|
||||
|
||||
# defined, set to local
|
||||
setconfig dest type local
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, set to remote
|
||||
setconfig dest type remote
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_REMOTEUSER}@${BN_REMOTEHOST}::${BN_BACKUPDIR}/testrdiff$"
|
||||
}
|
||||
|
||||
@test "check config parameters and dest/user and dest/host" {
|
||||
# user undefined, type remote, defaults empty
|
||||
setconfig dest type remote
|
||||
delconfig dest user
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Fatal: User must be specified for remote destination.'
|
||||
|
||||
# host undefined, type remote, defaults empty
|
||||
setconfig dest type remote
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
delconfig dest host
|
||||
testaction
|
||||
greplog 'Fatal: Host must be specified for remote destination.'
|
||||
|
||||
# user/host undefined, type local, defaults empty (noop)
|
||||
setconfig dest type local
|
||||
delconfig dest user
|
||||
delconfig dest host
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, type remote
|
||||
setconfig dest type remote
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_REMOTEUSER}@${BN_REMOTEHOST}::${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, type local (noop)
|
||||
setconfig dest type local
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
}
|
||||
|
||||
|
||||
@test "check config parameter dest/directory" {
|
||||
# undefined, defaults empty
|
||||
delconfig dest directory
|
||||
testaction
|
||||
greplog "Fatal: Destination directory not set$"
|
||||
|
||||
# defined, type local
|
||||
setconfig dest type local
|
||||
setconfig dest directory "$BN_BACKUPDIR"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_BACKUPDIR}/testrdiff$"
|
||||
|
||||
# defined, type remote, set to $BN_BACKUPDIR
|
||||
setconfig dest type remote
|
||||
setconfig dest directory "$BN_BACKUPDIR"
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\s/ ${BN_REMOTEUSER}@${BN_REMOTEHOST}::${BN_BACKUPDIR}/testrdiff$"
|
||||
}
|
||||
|
||||
@test "check config parameter dest/sshoptions" {
|
||||
# undefined, default empty
|
||||
delconfig dest sshoptions
|
||||
setconfig dest type remote
|
||||
setconfig dest directory "$BN_BACKUPDIR"
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\brdiff-backup\s\+--print-statistics\s"
|
||||
|
||||
# defined, set to -4
|
||||
setconfig dest sshoptions "-4"
|
||||
testaction
|
||||
greplog 'Debug: executing rdiff-backup$' "\brdiff-backup\s\+--remote-schema 'ssh -C -4 %s rdiff-backup --server'\s"
|
||||
}
|
||||
|
||||
@test "create local backup" {
|
||||
cleanup_backups local
|
||||
runaction
|
||||
greplog "Info: Successfully finished backing up source testrdiff$"
|
||||
}
|
||||
|
||||
@test "verify local backup" {
|
||||
rdiff-backup -v5 --verify "${BN_BACKUPDIR}/testrdiff" > "${BATS_TMPDIR}/_rdiff-verify.log"
|
||||
}
|
||||
|
||||
@test "verify number of files in local backup matches source" {
|
||||
SRC_FILES="$(find "${BN_SRCDIR}" -type f -not -path "${BN_SRCDIR}/var/*" | wc -l)"
|
||||
BACKUP_FILES="$(grep '^Verified SHA1 digest of' "${BATS_TMPDIR}/_rdiff-verify.log" | wc -l)"
|
||||
[ "$SRC_FILES" -eq "$BACKUP_FILES" ]
|
||||
}
|
||||
|
||||
@test "create remote backup" {
|
||||
cleanup_backups remote
|
||||
setconfig dest type remote
|
||||
setconfig dest host "$BN_REMOTEHOST"
|
||||
setconfig dest user "$BN_REMOTEUSER"
|
||||
runaction
|
||||
greplog "Info: Successfully finished backing up source testrdiff$"
|
||||
}
|
||||
|
||||
@test "verify remote backup" {
|
||||
rdiff-backup -v5 --verify "${BN_BACKUPDIR}/testrdiff" > "${BATS_TMPDIR}/_rdiff-verify.log"
|
||||
}
|
||||
|
||||
@test "verify number of files in remote backup matches source" {
|
||||
SRC_FILES="$(find "${BN_SRCDIR}" -type f -not -path "${BN_SRCDIR}/var/*" | wc -l)"
|
||||
BACKUP_FILES="$(grep '^Verified SHA1 digest of' "${BATS_TMPDIR}/_rdiff-verify.log" | wc -l)"
|
||||
[ "$SRC_FILES" -eq "$BACKUP_FILES" ]
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user