2018-07-13 03:26:48 +02:00
|
|
|
load common
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
begin_sys() {
|
2020-12-30 21:13:24 +01:00
|
|
|
apt-get -qq install debconf-utils hwinfo lvm2 cryptsetup-bin parted
|
2018-07-15 06:50:45 +02:00
|
|
|
|
2018-07-13 03:26:48 +02:00
|
|
|
cat << EOF > "${BATS_TMPDIR}/backup.d/test.sys"
|
|
|
|
when = manual
|
2018-07-15 06:50:45 +02:00
|
|
|
packages = yes
|
|
|
|
partitions = yes
|
|
|
|
hardware = yes
|
|
|
|
luksheaders = yes
|
|
|
|
lvm = yes
|
|
|
|
mbr = yes
|
2018-07-13 03:26:48 +02:00
|
|
|
bios = no
|
|
|
|
EOF
|
|
|
|
|
|
|
|
chmod 0640 "${BATS_TMPDIR}/backup.d/test.sys"
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
# Setup LVM
|
2020-12-30 21:13:24 +01:00
|
|
|
pvcreate /dev/sdc
|
|
|
|
vgcreate vgtest /dev/sdc
|
|
|
|
lvcreate -L 12M -n lvtest vgtest /dev/sdc
|
2020-12-27 17:33:05 +01:00
|
|
|
|
2020-12-30 21:13:24 +01:00
|
|
|
# Setup LUKS
|
|
|
|
parted -s /dev/sdd mklabel msdos mkpart p 1MiB 50% mkpart p 50% 100%
|
|
|
|
cryptsetup -q --type luks1 luksFormat /dev/sdd1 <<< 123test
|
|
|
|
cryptsetup -q --type luks2 luksFormat /dev/sdd2 <<< 123test
|
2020-12-30 21:46:38 +01:00
|
|
|
cryptsetup -q --type luks2 luksFormat /dev/sde <<< 123test
|
2018-07-15 06:50:45 +02:00
|
|
|
|
|
|
|
# Do backup
|
|
|
|
run backupninja -f "${BATS_TMPDIR}/backupninja.conf" --now --run "${BATS_TMPDIR}/backup.d/test.sys"
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
finish_sys() {
|
2018-07-13 03:26:48 +02:00
|
|
|
lvremove -f vgtest/lvtest
|
2018-07-15 06:50:45 +02:00
|
|
|
vgremove vgtest
|
2020-12-30 21:13:24 +01:00
|
|
|
pvremove /dev/sdc
|
|
|
|
dd if=/dev/zero of=/dev/sdc bs=512 count=1 conv=notrunc
|
|
|
|
dd if=/dev/zero of=/dev/sdd bs=512 count=1 conv=notrunc
|
2020-12-30 21:46:38 +01:00
|
|
|
dd if=/dev/zero of=/dev/sde bs=512 count=1 conv=notrunc
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
@test "action runs without errors" {
|
|
|
|
grep -q "Info: FINISHED: 1 actions run. 0 fatal. 0 error. 0 warning." "${BATS_TMPDIR}/log/backupninja.log"
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "system report is created" {
|
2018-07-13 03:26:48 +02:00
|
|
|
[ -s /var/backups/sysreport.txt ]
|
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "packages backup is made" {
|
2018-07-13 03:26:48 +02:00
|
|
|
[ -s /var/backups/dpkg-selections.txt ]
|
|
|
|
[ -s /var/backups/debconfsel.txt ]
|
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "partitions backup is made" {
|
2018-07-13 03:26:48 +02:00
|
|
|
[ -s /var/backups/partitions.sda.txt ]
|
2020-12-30 21:13:24 +01:00
|
|
|
[ -s /var/backups/partitions.sdd.txt ]
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
|
|
|
|
2018-07-15 06:50:45 +02:00
|
|
|
@test "mbr backup is made" {
|
|
|
|
[ -s /var/backups/mbr.sda.bin ]
|
|
|
|
file /var/backups/mbr.sda.bin | grep -q "DOS/MBR boot sector"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "hardware info backup is made" {
|
2018-07-13 03:26:48 +02:00
|
|
|
[ -s /var/backups/hardware.txt ]
|
|
|
|
}
|
|
|
|
|
2018-07-13 16:38:02 +02:00
|
|
|
@test "lvm backup is made" {
|
2018-07-13 03:26:48 +02:00
|
|
|
[ -d /var/backups/lvm ]
|
|
|
|
[ -s /var/backups/lvm/vgtest ]
|
|
|
|
grep -q 'contents = "Text Format Volume Group"' "/var/backups/lvm/vgtest"
|
|
|
|
}
|
|
|
|
|
2020-12-30 21:46:38 +01:00
|
|
|
@test "luksheaders v1 partition backup is made" {
|
2020-12-30 21:13:24 +01:00
|
|
|
file /var/backups/luksheader.sdd1.bin | grep -q "LUKS encrypted file"
|
2018-07-13 03:26:48 +02:00
|
|
|
}
|
2020-12-27 17:33:05 +01:00
|
|
|
|
2020-12-30 21:46:38 +01:00
|
|
|
@test "luksheaders v2 partition backup is made" {
|
2020-12-30 21:13:24 +01:00
|
|
|
file /var/backups/luksheader.sdd2.bin | grep -q "LUKS encrypted file"
|
2020-12-27 17:33:05 +01:00
|
|
|
}
|
2020-12-30 21:46:38 +01:00
|
|
|
|
|
|
|
@test "luksheaders v2 device backup is made" {
|
|
|
|
file /var/backups/luksheader.sde.bin | grep -q "LUKS encrypted file"
|
|
|
|
}
|