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
|
#!/bin/bash
. "$(dirname "$0")"/_common
break_debug=0
manual_fs=$1
test_fs=$mountable_fs
dd_count=$normal_size
[ -z $manual_fs ] || test_fs=$manual_fs
source_partition="/dev/sdb1"
target_partition="/dev/sdc1"
target_image="/test/partclone-test.img"
source_mountpoint="/test/source"
target_mountpoint="/test/target"
data_pool="/test/datapool/"
chfile="/test/checksum.log"
cchfile="/test/checksum_test.log"
if [ "X$SOURCEPART" != "X" ]; then
source_partition=$SOURCEPART
fi
if [ "X$TARGETPART" != "X" ]; then
target_partition=$TARGETPART
fi
#main
# clean partition
dd if=/dev/zero of=$source_partition bs=1M count=4096
dd if=/dev/zero of=$target_partition bs=1M count=4096
for fs in $test_fs; do
echo -e "Advanced $fs test"
echo -e "==========================\n"
mkdir -p $source_mountpoint $target_mountpoint $data_pool
umount $target_mountpoint $source_mountpoint
set -e
ptlfs=$(_ptlname $fs)
mkfs=$(_findmkfs $fs)
logfile="/test/clone-$fs.log"
echo -e "\n__format__ $source_partition as $fs partition\n"
echo -e " mkfs.$fs `eval echo "$"mkfs_option_for_$fs""` $source_partition\n"
_ptlbreak
$mkfs `eval echo "$"mkfs_option_for_$fs""` $source_partition
_check_return_code
echo -e "\n__prepare__ data to clone\n"
_ptlbreak
echo -e "\n mount -t $fs $source_partition $source_mountpoint\n"
mount -t $fs $source_partition $source_mountpoint
set +e
# rsync error while rsync to vfat
# rsync error while rsync to exfat
# rsync -arl $data_pool $source_mountpoint
# use cp -r
echo -e "\n cp -r $data_pool/* $source_mountpoint\n"
cp -r $data_pool/* $source_mountpoint
set -e
sync
echo -e "\n find . -type f -exec md5sum '{}' \; > $chfile\n"
pushd $source_mountpoint
find . -type f -exec md5sum '{}' \; > $chfile
popd
umount $source_mountpoint
echo -e "\nmd5sum done\n"
echo -e "\n__device to device clone__, $source_partition to $target_partition\n"
echo -e " $ptlfs -d -b -s $source_partition -o $target_partition -L $logfile\n"
_ptlbreak
$ptlfs -q -d -b -s $source_partition -o $target_partition -L $logfile
_check_return_code
echo -e "\n__check data__\n"
_ptlbreak
mount -t $fs $target_partition $target_mountpoint
pushd $target_mountpoint
echo -e "\n md5sum --quiet -c $chfile 2>&1 > $cchfile\n"
md5sum --quiet -c $chfile 2>&1 > $cchfile
popd
umount $target_mountpoint
echo -e "\n__done__\n"
_check_return_code
echo -e "\n__device to image clone__, $source_partition to $target_image\n"
echo -e " $ptlfs -d -c -s $source_partition -O $target_image -L $logfile -a 2 -k 64\n"
_ptlbreak
$ptlfs -q -d -c -s $source_partition -O $target_image -L $logfile -a 2 -k 64
_check_return_code
echo -e "\n__restore image to device__, $target_image to $target_partition\n"
echo -e " $ptlfs -d -r -s $target_image -o $target_partition -L $logfile\n"
_ptlbreak
dd if=/dev/zero of=$target_partition bs=512 count=32
$ptlfs -q -d -r -s $target_image -o $target_partition -L $logfile
_check_return_code
echo -e "\n__check data__\n"
_ptlbreak
mount -t $fs $target_partition $target_mountpoint
pushd $target_mountpoint
echo -e "\n md5sum --quiet -c $chfile 2>&1 > $cchfile\n"
md5sum --quiet -c $chfile 2>&1 > $cchfile
popd
umount $target_mountpoint
echo -e "\n__done__\n"
_check_return_code
echo -e "\nclear tmp files\n"
_ptlbreak
set +e
umount $target_mountpoint $source_mountpoint
rm -r $target_mountpoint $source_mountpoint $logfile $chfile $cchfile $target_image
_check_return_code
echo -e "\n$fs test ok\n"
done
echo -e "\nFinish!\n\n"
|