blob: 517a458fc3c1686c145ca0f0e6427a551437b7d8 (
plain)
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
|
#!/bin/sh
source ./assert.sh
PROGRAM_EXEC="$1"
function files_are_the_same()
{
[ -z "$(diff "$1" "$2")" ]
}
rm -f input backedup_input ref out
# Create a four-sector reference file (the original file)
dd if=/dev/zero of=ref bs=512 count=4 1>/dev/null 2>&1
# Change the orignal file to make it an input file for differential backup
# There will be four different sectors in the input file
cp ref input
# The first sector will have the 0th byte chaged
printf '\xFF' | dd of=input bs=1 count=1 seek=0 conv=notrunc 1>/dev/null 2>&1
# The second sector will have no changes
# The third sector will have the last byte changed
printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 3) - 1 )) conv=notrunc 1>/dev/null 2>&1
# The fourth sector will have the middle byte changed
printf '\xFF' | dd of=input bs=1 count=1 seek=$(( (512 * 4) - (512 / 2) )) conv=notrunc 1>/dev/null 2>&1
assert "" "" 0 $PROGRAM_EXEC backup -s 512 input ref out
if ! files_are_the_same out 400-expected_backup_output.bin; then
echo "assert: Backup output file differs from the expected one"
exit 1
fi
# Modify the file to backup (the input file used in the backup phase)
cp input backedup_input
cp ref input
if ! files_are_the_same ref input; then
echo "assert: The input file must be the same as the reference one before restoring it"
exit 1
fi
assert "" "" 0 $PROGRAM_EXEC restore -s 512 out input
if ! files_are_the_same input backedup_input; then
echo "assert: Cannot restore the backup"
exit 1
fi
rm -f input backedup_input ref out
exit 0
|