2017-05-17 01:41:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Test btrfs-image with multiple devices filesystem and verify that restoring
|
|
|
|
# the created image works against a single device.
|
|
|
|
|
2018-02-08 06:34:19 +00:00
|
|
|
source "$TEST_TOP/common"
|
2017-05-17 01:41:31 +00:00
|
|
|
|
|
|
|
check_prereq btrfs-image
|
|
|
|
check_prereq mkfs.btrfs
|
|
|
|
check_prereq btrfs
|
|
|
|
|
|
|
|
setup_root_helper
|
|
|
|
|
2019-09-04 13:29:47 +00:00
|
|
|
setup_loopdevs 3
|
2019-07-03 20:01:25 +00:00
|
|
|
prepare_loopdevs
|
|
|
|
loop1=${loopdevs[1]}
|
|
|
|
loop2=${loopdevs[2]}
|
2019-09-04 13:29:47 +00:00
|
|
|
loop3=${loopdevs[3]}
|
2017-05-17 01:41:31 +00:00
|
|
|
|
|
|
|
# Create the test file system.
|
|
|
|
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/mkfs.btrfs" -f "$loop1" "$loop2"
|
|
|
|
run_check $SUDO_HELPER mount "$loop1" "$TEST_MNT"
|
|
|
|
run_check $SUDO_HELPER dd bs=1M count=1 if=/dev/zero of="$TEST_MNT/foobar"
|
2019-09-04 13:29:47 +00:00
|
|
|
orig_md5=$(run_check_stdout stat "$TEST_MNT/foobar" | md5sum | cut -d ' ' -f 1)
|
2017-05-17 01:41:31 +00:00
|
|
|
run_check $SUDO_HELPER umount "$TEST_MNT"
|
|
|
|
|
|
|
|
# Create the image to restore later.
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/btrfs-image" "$loop1" "$IMAGE"
|
2017-05-17 01:41:31 +00:00
|
|
|
|
|
|
|
# Wipe out the filesystem from the devices, restore the image on a single
|
|
|
|
# device, check everything works and file foobar is there and with 1Mb of
|
|
|
|
# zeroes.
|
2018-03-23 15:34:30 +00:00
|
|
|
run_check $SUDO_HELPER wipefs -a "$loop1"
|
|
|
|
run_check $SUDO_HELPER wipefs -a "$loop2"
|
2017-05-17 01:41:31 +00:00
|
|
|
|
2019-09-04 13:29:47 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/btrfs-image" -r "$IMAGE" "$loop3"
|
2017-05-17 01:41:31 +00:00
|
|
|
|
2018-11-27 08:38:28 +00:00
|
|
|
# Run check to make sure there is nothing wrong for the recovered image
|
2019-09-04 13:29:47 +00:00
|
|
|
run_check $SUDO_HELPER "$TOP/btrfs" check "$loop3"
|
2018-11-27 08:38:28 +00:00
|
|
|
|
2019-09-04 13:29:47 +00:00
|
|
|
run_check $SUDO_HELPER mount "$loop3" "$TEST_MNT"
|
|
|
|
new_md5=$(run_check_stdout stat "$TEST_MNT/foobar" | md5sum | cut -d ' ' -f 1)
|
2017-05-17 01:41:31 +00:00
|
|
|
run_check $SUDO_HELPER umount "$TEST_MNT"
|
|
|
|
|
2019-07-03 20:01:25 +00:00
|
|
|
cleanup_loopdevs
|
2017-05-17 01:41:31 +00:00
|
|
|
|
|
|
|
# Compare the file digests.
|
2018-03-23 15:34:30 +00:00
|
|
|
[ "$orig_md5" == "$new_md5" ] || _fail "File digests do not match"
|