backupninja/test/rsync.bats

149 lines
4.1 KiB
Plaintext
Raw Normal View History

2021-01-01 00:57:46 +01:00
load common
begin_rsync() {
install_pkgs debootstrap rsync
2021-01-07 02:37:54 +01:00
if [ ! -d "$BN_SRCDIR" ]; then
debootstrap --variant=minbase testing "$BN_SRCDIR"
2021-01-01 00:57:46 +01:00
fi
}
setup_rsync() {
cat << EOF > "${BATS_TMPDIR}/backup.d/test.rsync"
when = manual
[general]
log = ${BATS_TMPDIR}/log/rsync.log
2021-01-07 02:37:54 +01:00
mountpoint = $BN_BACKUPDIR
backupdir = testrsync
2021-01-01 00:57:46 +01:00
format =
[source]
from = local
2021-01-07 02:37:54 +01:00
include = $BN_SRCDIR
exclude = var
2021-01-01 00:57:46 +01:00
[dest]
dest = local
host =
user =
id_file = /root/.ssh/id_ed25519
EOF
chmod 0640 "${BATS_TMPDIR}/backup.d/test.rsync"
}
finish_rsync() {
cleanup_backups local remote
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "create local backup, short format" {
cleanup_backups local
2021-01-07 02:37:54 +01:00
setconfig general format short
mkdir -p "${BN_BACKUPDIR}/testrsync"
runaction
greplog "Debug: Rsync transfer of $BN_SRCDIR finished successfully.$"
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify local backup, short format" {
run rsync -ain --exclude var --delete "${BN_SRCDIR}/" "${BN_BACKUPDIR}/testrsync${BN_SRCDIR}/bntest.0/"
2021-01-01 00:57:46 +01:00
[ "$status" -eq 0 ]
2021-01-07 02:37:54 +01:00
[ "$output" == ".d..t...... ./" ]
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify local backup rotation, short format" {
2021-01-01 00:57:46 +01:00
skip "not implemented"
}
2021-01-07 02:37:54 +01:00
@test "create local backup, long format" {
cleanup_backups local
2021-01-07 02:37:54 +01:00
setconfig general format long
mkdir -p "${BN_BACKUPDIR}/testrsync"
runaction
greplog "Debug: Rsync transfer of $BN_SRCDIR finished successfully.$"
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify local backup, long format" {
run rsync -ain --exclude var --delete "${BN_SRCDIR}/" "${BN_BACKUPDIR}/testrsync${BN_SRCDIR}/daily.1/"
2021-01-01 00:57:46 +01:00
[ "$status" -eq 0 ]
2021-01-07 02:37:54 +01:00
[ "$output" == ".d..t...... ./" ]
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify local backup rotation, long format" {
2021-01-01 00:57:46 +01:00
skip "not implemented"
}
2021-01-07 02:37:54 +01:00
@test "create local backup, mirror format" {
cleanup_backups local
setconfig general format mirror
mkdir -p "${BN_BACKUPDIR}/testrsync"
runaction
greplog "Debug: Rsync transfer of $BN_SRCDIR finished successfully.$"
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify local backup, mirror format" {
run rsync -ain --exclude var --delete "${BN_SRCDIR}/" "${BN_BACKUPDIR}/testrsync${BN_SRCDIR}/"
[ "$status" -eq 0 ]
[ "$output" == ".d..t...... ./" ]
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "create remote backup, short format" {
cleanup_backups remote
2021-01-07 02:37:54 +01:00
setconfig general format short
setconfig dest dest remote
setconfig dest host "$BN_REMOTEHOST"
setconfig dest user "$BN_REMOTEUSER"
remote_command "mkdir -p \"${BN_BACKUPDIR}/testrsync\""
runaction
greplog "Debug: Rsync transfer of $BN_SRCDIR finished successfully.$"
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify remote backup, short format" {
run rsync -ain --exclude var --delete "${BN_SRCDIR}/" "${BN_REMOTEUSER}@${BN_REMOTEHOST}:${BN_BACKUPDIR}/testrsync${BN_SRCDIR}/bntest.0"
[ "$status" -eq 0 ]
! echo "$output" | grep -qv '^skipping non-regular file'
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify remote backup rotation, short format" {
2021-01-01 00:57:46 +01:00
skip "not implemented"
}
2021-01-07 02:37:54 +01:00
@test "create remote backup, long format" {
cleanup_backups remote
setconfig general format long
setconfig dest dest remote
setconfig dest host "$BN_REMOTEHOST"
setconfig dest user "$BN_REMOTEUSER"
remote_command "mkdir -p \"${BN_BACKUPDIR}/testrsync\""
runaction
greplog "Debug: Rsync transfer of $BN_SRCDIR finished successfully.$"
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify remote backup, long format" {
run rsync -ain --exclude var --delete "${BN_SRCDIR}/" "${BN_REMOTEUSER}@${BN_REMOTEHOST}:${BN_BACKUPDIR}/testrsync${BN_SRCDIR}/daily.1"
[ "$status" -eq 0 ]
! echo "$output" | grep -qv '^skipping non-regular file'
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify remote backup rotation, long format" {
2021-01-01 00:57:46 +01:00
skip "not implemented"
}
2021-01-07 02:37:54 +01:00
@test "create remote backup, mirror format" {
cleanup_backups remote
2021-01-07 02:37:54 +01:00
setconfig general format mirror
setconfig dest dest remote
setconfig dest host "$BN_REMOTEHOST"
setconfig dest user "$BN_REMOTEUSER"
remote_command "mkdir -p \"${BN_BACKUPDIR}/testrsync\""
runaction
greplog "Debug: Rsync transfer of $BN_SRCDIR finished successfully.$"
2021-01-01 00:57:46 +01:00
}
2021-01-07 02:37:54 +01:00
@test "verify remote backup, mirror format" {
run rsync -ain --exclude var --delete "${BN_SRCDIR}/" "${BN_REMOTEUSER}@${BN_REMOTEHOST}:${BN_BACKUPDIR}/testrsync${BN_SRCDIR}/"
[ "$status" -eq 0 ]
! echo "$output" | grep -qv '^skipping non-regular file'
2021-01-01 00:57:46 +01:00
}