File: mini_clone_restore_test

package info (click to toggle)
partclone 0.3.36%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,276 kB
  • sloc: ansic: 136,343; sh: 4,828; xml: 2,106; makefile: 501; asm: 383; perl: 106; sed: 16
file content (135 lines) | stat: -rwxr-xr-x 3,383 bytes parent folder | download | duplicates (2)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set -e

usage(){
    echo "Usage: $0 [-b BLOCK_SIZE] [-f FILE_SIZE] [TARGET_FILESYSTEM]"
    exit 0
}

. "$(dirname "$0")"/_common

## blocks/checksum to test various patterns
cs_a=(0   1   1   1   1     1)
cs_k=(0  17   1  64   0  3097)
cs_s=${#cs_k[*]}               # array size
cs_i=0

## file system
normal_fs="ext2 ext3 ext4 vfat exfat minix"
featured_fs="$normal_fs jfs xfs reiserfs hfsplus"
extra_fs="$featured_fs ufs vmfs reiser4 ntfs btrfs"

test_fs=$formatable_fs

# additional options
OPT=$(getopt -o b:f:h --long block-size:,file-size:,help -- "$@")
if [ $? != 0 ] ; then
    exit 1
fi
eval set -- "$OPT"

file_size=0
block_size=0
while true
do
    case "$1" in
	-b|--block-size)
	    block_size=$(_convert_to_bytes $2)
	    shift 2
	;;
	-f|--file-size)
	    file_size=$(_convert_to_bytes $2)
	    shift 2
	;;
	-h|--help)
	    usage
	;;
	--)
	    shift
	    break
	;;
	*)
	    exit 1
	;;
    esac
done

manual_fs=$@
[ -z "$manual_fs" ] || test_fs=$manual_fs

#main
for fs in $test_fs; do

    cs_i=$(( (cs_i + 1) % cs_s))
    a=${cs_a[$cs_i]}
    k=${cs_k[$cs_i]}

    echo -e "Basic $fs test"
    echo -e "==========================\n"
    ptlfs=$(_ptlname $fs)
    mkfs=$(_findmkfs $fs)
    if [ $file_size -ne 0 -a $block_size -ne 0 ]; then
	dd_count=$(($file_size / $block_size))
	dd_bs=$block_size
    elif [ $block_size -ne 0 ]; then
	dd_bs=$block_size
    elif [ $file_size -ne 0 ]; then
	dd_count=$(($file_size / $dd_bs))
    else
	dd_count=$(_test_size $fs)
    fi
    echo -e "\ncreate raw file $raw\n"
    _ptlbreak
    [ -f $raw ] && rm $raw
    echo -e "    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count\n"
    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count

    echo -e "\n\nformat $raw as $fs raw partition\n"
    echo -e "    $mkfs `eval echo "$"mkfs_option_for_$fs""` $raw\n"
    _ptlbreak
    $mkfs `eval echo "$"mkfs_option_for_$fs""` $raw

    echo -e "\nclone $raw to $img\n"
    [ -f $img ] && rm $img
    echo -e "    $ptlfs -d -c -s $raw -O $img -F -L $logfile -a $a -k $k"
    _ptlbreak
    $ptlfs -d -c -s $raw -O $img -F -L $logfile -a $a -k $k
    _check_return_code

    echo -e "\n\ndo image checking\n"
    echo -e "    $ptlchkimg -s $img -L $logfile\n"
    _ptlbreak
    $ptlchkimg -s $img -L $logfile
    _check_return_code

    echo -e "\n\ncreate raw file $raw for restore\n"
    _ptlbreak
    [ -f $raw ] && rm $raw
    echo -e "    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count\n"
    dd if=/dev/zero of=$raw bs=$dd_bs count=$dd_count

    echo -e "\n\nrestore $img to $raw\n"
    echo -e "    $ptlrestore -s $img -O $raw -C -F -L $logfile\n"
    _ptlbreak
    $ptlrestore -s $img -O $raw -C -F -L $logfile
    _check_return_code

    [ -f $raw_restore ] && rm $raw_restore
    echo -e "    dd if=/dev/zero of=$raw_restore bs=$dd_bs count=$dd_count\n"
    dd if=/dev/zero of=$raw_restore bs=$dd_bs count=$dd_count
    echo -e "\n\ndirect clone $raw to $raw_restore\n"
    echo -e "    $ptlfs -d -b -s $raw -O $raw_restore -L $logfile\n"
    _ptlbreak
    $ptlfs -d -b -s $raw -O $raw_restore  -L $logfile
    _check_return_code


    echo -e "\n\n$fs test ok\n"
    echo -e "\nclear tmp files $img $raw $logfile $md5 $raw_restore\n"
    _ptlbreak
    rm -f $img $raw $logfile $md5 $raw_restore
    echo -e "\nfile system $fs test done\n"

    echo -e "\nfile system $fs test done\n"
done
echo -e "\nFinish!\n"