File: test.sh

package info (click to toggle)
btrfs-progs 6.17.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,612 kB
  • sloc: ansic: 127,282; sh: 7,915; python: 1,384; makefile: 900; asm: 296
file content (99 lines) | stat: -rwxr-xr-x 3,607 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
#
# Receive in reverse direction must not throw an error if it can find an
# earlier "sent" parent.  In general, shows a backup+sync setup between two (or
# more) PCs with an external drive.

source "$TEST_TOP/common"

check_prereq mkfs.btrfs
check_prereq btrfs
check_global_prereq dd

declare -a roots
i_pc1=1
# An external drive used to backup and carry profile.
i_ext=2
i_pc2=3
roots[$i_pc1]="$TEST_MNT/pc1"
roots[$i_ext]="$TEST_MNT/external"
roots[$i_pc2]="$TEST_MNT/pc2"

setup_root_helper
mkdir -p "${roots[@]}"
setup_loopdevs 3
prepare_loopdevs
for i in `seq 3`; do
	TEST_DEV="${loopdevs[$i]}"
	TEST_MNT="${roots[$i]}"
	run_check_mkfs_test_dev
	run_check_mount_test_dev
	run_check $SUDO_HELPER mkdir -p "$TEST_MNT/.snapshots"
done

run_check_update_file()
{
	run_check $SUDO_HELPER cp --reflink "${roots[$1]}/profile/$2" "${roots[$1]}/profile/staging"
	run_check $SUDO_HELPER dd if=/dev/urandom conv=notrunc bs=4K count=4 seek=$3 "of=${roots[$1]}/profile/staging"
	run_check $SUDO_HELPER mv "${roots[$1]}/profile/staging" "${roots[$1]}/profile/$2"
}
run_check_copy_snapshot_with_diff()
{
	_mktemp_local send.data
	run_check $SUDO_HELPER "$TOP/btrfs" send -f send.data -p "${roots[$1]}/.snapshots/$2" "${roots[$1]}/.snapshots/$3"
	run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.data "${roots[$4]}/.snapshots"
}
run_check_backup_profile()
{
	run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "${roots[$1]}/profile" "${roots[$1]}/.snapshots/$3"
	run_check_copy_snapshot_with_diff "$1" "$2" "$3" "$i_ext"
	# Don't keep old snapshot in pc
	run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "${roots[$1]}/.snapshots/$2"
}
run_check_restore_profile()
{
	run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot "${roots[$1]}/.snapshots/$2" "${roots[$1]}/profile"
}
run_check_copy_fresh_backup_and_replace_profile()
{
    run_check_copy_snapshot_with_diff "$i_ext" "$2" "$3" "$1"
    # IRL, it would be a nice idea to make a backup snapshot before deleting.
    run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "${roots[$1]}/profile"
    run_check_restore_profile "$1" "$3"
    # Don't keep old snapshot in pc
    run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete "${roots[$1]}/.snapshots/$2"
}


run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "${roots[$i_pc1]}/profile"
run_check $SUDO_HELPER dd if=/dev/urandom bs=4K count=16 "of=${roots[$i_pc1]}/profile/day1"
run_check $SUDO_HELPER "$TOP/btrfs" subvolume snapshot -r "${roots[$i_pc1]}/profile" "${roots[$i_pc1]}/.snapshots/day1"
_mktemp_local send.data
run_check $SUDO_HELPER "$TOP/btrfs" send -f send.data "${roots[$i_pc1]}/.snapshots/day1"
run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.data "${roots[$i_ext]}/.snapshots"

run_check_update_file "$i_pc1" day1 2
run_check_backup_profile "$i_pc1" day1 day2

_mktemp_local send.data
run_check $SUDO_HELPER "$TOP/btrfs" send -f send.data "${roots[$i_ext]}/.snapshots/day2"
run_check $SUDO_HELPER "$TOP/btrfs" receive -f send.data "${roots[$i_pc2]}/.snapshots"
run_check_restore_profile "$i_pc2" day2
run_check_update_file "$i_pc2" day1 3
run_check_backup_profile "$i_pc2" day2 day3

run_check_update_file "$i_pc2" day1 4
run_check_backup_profile "$i_pc2" day3 day4

run_check_copy_fresh_backup_and_replace_profile "$i_pc1" day2 day4
run_check_update_file "$i_pc1" day1 5
run_check_backup_profile "$i_pc1" day4 day5

run_check_copy_fresh_backup_and_replace_profile "$i_pc2" day4 day5
run_check_update_file "$i_pc2" day1 6
run_check_backup_profile "$i_pc2" day5 day6

run_check_umount_test_dev "${loopdevs[@]}"
rmdir "${roots[@]}"
rm -f send.data
cleanup_loopdevs