|
@@ -74,7 +74,7 @@ EOF
|
|
|
exit 0
|
|
exit 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-OPTS=$(getopt c:d:e:DhjJPr:uTvVz $*)
|
|
|
|
|
|
|
+OPTS=$(getopt c:d:e:FDhjJPr:uTvVz $*)
|
|
|
#Test les paramètres
|
|
#Test les paramètres
|
|
|
if [ $? != 0 ]
|
|
if [ $? != 0 ]
|
|
|
then
|
|
then
|
|
@@ -93,6 +93,7 @@ COMPRESSION_SUFFIX=".xz"
|
|
|
VERBOSE_OPTION=""
|
|
VERBOSE_OPTION=""
|
|
|
EXCLUDE_PATTERNS=""
|
|
EXCLUDE_PATTERNS=""
|
|
|
KEEP_PARTITIONS=""
|
|
KEEP_PARTITIONS=""
|
|
|
|
|
+FAKE_DEVICE=""
|
|
|
|
|
|
|
|
while true ; do
|
|
while true ; do
|
|
|
case "$1" in
|
|
case "$1" in
|
|
@@ -102,6 +103,8 @@ while true ; do
|
|
|
;;
|
|
;;
|
|
|
-e) EXCLUDE_PATTERNS="$EXCLUDE_PATTERNS $2" ; shift ; shift
|
|
-e) EXCLUDE_PATTERNS="$EXCLUDE_PATTERNS $2" ; shift ; shift
|
|
|
;;
|
|
;;
|
|
|
|
|
+ -F) FAKE_DEVICE="1"; shift
|
|
|
|
|
+ ;;
|
|
|
-r) SOURCE_DIR="$2" ; shift ; shift
|
|
-r) SOURCE_DIR="$2" ; shift ; shift
|
|
|
;;
|
|
;;
|
|
|
-u) COMPRESSION_ALGORITHM="" ; COMPRESSION_SUFFIX="" ; shift
|
|
-u) COMPRESSION_ALGORITHM="" ; COMPRESSION_SUFFIX="" ; shift
|
|
@@ -147,13 +150,19 @@ do_restore_disk(){
|
|
|
echo "Restoring disk image from $SOURCE_DIR to $DISK_DEVICE"
|
|
echo "Restoring disk image from $SOURCE_DIR to $DISK_DEVICE"
|
|
|
if [[ "$KEEP_PARTITIONS" != "1" ]] ; then
|
|
if [[ "$KEEP_PARTITIONS" != "1" ]] ; then
|
|
|
echo "Restoring boot sector backup"
|
|
echo "Restoring boot sector backup"
|
|
|
- test "1" != "$DEBUG" && dcfldd if=$SOURCE_DIR/boot-sector.img of=$DISK_DEVICE || exit 44
|
|
|
|
|
|
|
+ if [[ "1" != "$DEBUG" ]] ; then
|
|
|
|
|
+ dcfldd if=$SOURCE_DIR/boot-sector.img of=$DISK_DEVICE || exit 44
|
|
|
|
|
+ fi
|
|
|
|
|
|
|
|
echo "Restoring partition table backup"
|
|
echo "Restoring partition table backup"
|
|
|
- test "1" != "$DEBUG" && sfdisk $DISK_DEVICE < $SOURCE_DIR/partition-table.sfdisk || exit 45
|
|
|
|
|
|
|
+ if [[ "1" != "$DEBUG" ]] ; then
|
|
|
|
|
+ sfdisk $DISK_DEVICE < $SOURCE_DIR/partition-table.sfdisk || exit 45
|
|
|
|
|
+ fi
|
|
|
|
|
|
|
|
echo "Updating from partition information"
|
|
echo "Updating from partition information"
|
|
|
- test "1" != "$DEBUG" && hdparm -z $DISK_DEVICE
|
|
|
|
|
|
|
+ if [[ "1" != "$DEBUG" ]] ; then
|
|
|
|
|
+ hdparm -z $DISK_DEVICE
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
ls $SOURCE_DIR/partition*.tar$COMPRESSION_SUFFIX > /dev/null 2>&1
|
|
ls $SOURCE_DIR/partition*.tar$COMPRESSION_SUFFIX > /dev/null 2>&1
|
|
@@ -178,14 +187,16 @@ do_restore_disk(){
|
|
|
#First get the partition type
|
|
#First get the partition type
|
|
|
partition_type=$(cat $partition_type_file)
|
|
partition_type=$(cat $partition_type_file)
|
|
|
echo "Formating $partition_dev with type $partition_type"
|
|
echo "Formating $partition_dev with type $partition_type"
|
|
|
- test "1" != "$DEBUG" && mkfs -t $partition_type $partition_dev
|
|
|
|
|
- test "$?" == 0 || exit $?
|
|
|
|
|
|
|
+ if [[ "1" != "$DEBUG" ]] ; then
|
|
|
|
|
+ mkfs -t $partition_type $partition_dev
|
|
|
|
|
+ test "$?" == 0 || exit $?
|
|
|
|
|
+ fi
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
mount_dir_name="diskimg-$backup_basename"
|
|
mount_dir_name="diskimg-$backup_basename"
|
|
|
mountpoint_dir="/mnt/$mount_dir_name"
|
|
mountpoint_dir="/mnt/$mount_dir_name"
|
|
|
test "1" = "$VERBOSE" && echo "Mounting $partition_dev to $mountpoint_dir"
|
|
test "1" = "$VERBOSE" && echo "Mounting $partition_dev to $mountpoint_dir"
|
|
|
- mkdir -p $mountpoint_dir
|
|
|
|
|
|
|
+ [[ "$FAKE_DEVICE" != "1" ]] && mkdir -p $mountpoint_dir
|
|
|
test "$?" == 0 || exit $?
|
|
test "$?" == 0 || exit $?
|
|
|
mount $partition_dev $mountpoint_dir
|
|
mount $partition_dev $mountpoint_dir
|
|
|
test "$?" == 0 || exit $?
|
|
test "$?" == 0 || exit $?
|
|
@@ -198,10 +209,12 @@ do_restore_disk(){
|
|
|
|
|
|
|
|
test "$?" == 0 || exit $?
|
|
test "$?" == 0 || exit $?
|
|
|
test "1" = "$VERBOSE" && echo "Un-mounting $partition_dev"
|
|
test "1" = "$VERBOSE" && echo "Un-mounting $partition_dev"
|
|
|
- umount $partition_dev
|
|
|
|
|
- test "$?" == 0 || exit $?
|
|
|
|
|
- rmdir $mountpoint_dir
|
|
|
|
|
- test "$?" == 0 || exit $?
|
|
|
|
|
|
|
+ if [[ "$FAKE_DEVICE" != "1" ]] ; then
|
|
|
|
|
+ umount $partition_dev
|
|
|
|
|
+ test "$?" == 0 || exit $?
|
|
|
|
|
+ rmdir $mountpoint_dir
|
|
|
|
|
+ test "$?" == 0 || exit $?
|
|
|
|
|
+ fi
|
|
|
done
|
|
done
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -237,7 +250,7 @@ backup_mounted_volume(){
|
|
|
echo $part_type > $TARGET_DIR/$part_type_filename
|
|
echo $part_type > $TARGET_DIR/$part_type_filename
|
|
|
|
|
|
|
|
backup_filename="$backup_basename.tar$COMPRESSION_SUFFIX "
|
|
backup_filename="$backup_basename.tar$COMPRESSION_SUFFIX "
|
|
|
- echo "Creating backup for $partition_dev into $backup_filename"
|
|
|
|
|
|
|
+ echo "--- Creating backup for $partition_dev into $backup_filename ---"
|
|
|
mount_dir_name="diskimg-$backup_basename"
|
|
mount_dir_name="diskimg-$backup_basename"
|
|
|
mountpoint_dir="/mnt/$mount_dir_name"
|
|
mountpoint_dir="/mnt/$mount_dir_name"
|
|
|
test "1" = "$VERBOSE" && echo "Mounting $partition_dev to $mountpoint_dir"
|
|
test "1" = "$VERBOSE" && echo "Mounting $partition_dev to $mountpoint_dir"
|
|
@@ -310,15 +323,13 @@ backup_disk(){
|
|
|
#Partition type
|
|
#Partition type
|
|
|
echo "Saving partition type"
|
|
echo "Saving partition type"
|
|
|
part_type=`lsblk -lno NAME,FSTYPE $partition_dev | grep $(basename $partition_dev) | awk '{print $2}'`
|
|
part_type=`lsblk -lno NAME,FSTYPE $partition_dev | grep $(basename $partition_dev) | awk '{print $2}'`
|
|
|
- #part_type=`lsblk -lno NAME,FSTYPE $partition_dev | grep $DISK_DEVICE | print '{print $2}'`
|
|
|
|
|
case $part_type in
|
|
case $part_type in
|
|
|
crypto_LUKS)
|
|
crypto_LUKS)
|
|
|
#We extra steps here:
|
|
#We extra steps here:
|
|
|
#First decipher the luks partition:
|
|
#First decipher the luks partition:
|
|
|
- echo '###'$part_type'###'
|
|
|
|
|
ensure_crypt_part_is_opened $partition_dev $backup_basename
|
|
ensure_crypt_part_is_opened $partition_dev $backup_basename
|
|
|
|
|
+ #The inner partition and device may have changed
|
|
|
part_type=${_UNCRYPTED_TYPE}
|
|
part_type=${_UNCRYPTED_TYPE}
|
|
|
- echo '***'$part_type'***'
|
|
|
|
|
device_to_mount=${_UNCRYPTED_VOL}
|
|
device_to_mount=${_UNCRYPTED_VOL}
|
|
|
backup_mounted_volume $backup_basename $device_to_mount $part_type
|
|
backup_mounted_volume $backup_basename $device_to_mount $part_type
|
|
|
;;
|
|
;;
|