|
@@ -47,6 +47,7 @@ OPTIONS:
|
|
|
-c creates the backup using the given TARGET_DIR value
|
|
-c creates the backup using the given TARGET_DIR value
|
|
|
-d the DISK_DEVICE from/to process
|
|
-d the DISK_DEVICE from/to process
|
|
|
-e exclude file patterns from tar (creation). Re-use for several values (e.g -e /foo/bar -e /my/path)
|
|
-e exclude file patterns from tar (creation). Re-use for several values (e.g -e /foo/bar -e /my/path)
|
|
|
|
|
+ -u uncompressed image (disables compression)
|
|
|
-z uses gzip compression
|
|
-z uses gzip compression
|
|
|
-j uses bzip2 compression
|
|
-j uses bzip2 compression
|
|
|
-P keep existing partitions
|
|
-P keep existing partitions
|
|
@@ -54,6 +55,7 @@ OPTIONS:
|
|
|
-J uses XZ compression (DEFAULT)
|
|
-J uses XZ compression (DEFAULT)
|
|
|
-T skip tar archive creation (useful if backup only partition layout)
|
|
-T skip tar archive creation (useful if backup only partition layout)
|
|
|
-v Verbose
|
|
-v Verbose
|
|
|
|
|
+ -v Very verbose (debug mode)
|
|
|
-D dry run
|
|
-D dry run
|
|
|
|
|
|
|
|
EXAMPLES:
|
|
EXAMPLES:
|
|
@@ -72,7 +74,7 @@ EOF
|
|
|
exit 0
|
|
exit 0
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-OPTS=$(getopt c:d:e:DhjJPr:Tvz $*)
|
|
|
|
|
|
|
+OPTS=$(getopt c:d:e:DhjJPr:uTvVz $*)
|
|
|
#Test les paramètres
|
|
#Test les paramètres
|
|
|
if [ $? != 0 ]
|
|
if [ $? != 0 ]
|
|
|
then
|
|
then
|
|
@@ -87,7 +89,7 @@ DISK_DEVICE=""
|
|
|
TARGET_DIR=""
|
|
TARGET_DIR=""
|
|
|
SOURCE_DIR=""
|
|
SOURCE_DIR=""
|
|
|
COMPRESSION_ALGORITHM="-J"
|
|
COMPRESSION_ALGORITHM="-J"
|
|
|
-COMPRESSION_SUFFIX="xz"
|
|
|
|
|
|
|
+COMPRESSION_SUFFIX=".xz"
|
|
|
VERBOSE_OPTION=""
|
|
VERBOSE_OPTION=""
|
|
|
EXCLUDE_PATTERNS=""
|
|
EXCLUDE_PATTERNS=""
|
|
|
KEEP_PARTITIONS=""
|
|
KEEP_PARTITIONS=""
|
|
@@ -102,12 +104,19 @@ while true ; do
|
|
|
;;
|
|
;;
|
|
|
-r) SOURCE_DIR="$2" ; shift ; shift
|
|
-r) SOURCE_DIR="$2" ; shift ; shift
|
|
|
;;
|
|
;;
|
|
|
- -z) COMPRESSION_ALGORITHM="-z" ; COMPRESSION_SUFFIX="gz" ; shift
|
|
|
|
|
|
|
+ -u) COMPRESSION_ALGORITHM="" ; COMPRESSION_SUFFIX="" ; shift
|
|
|
;;
|
|
;;
|
|
|
- -j) COMPRESSION_ALGORITHM="-j"; COMPRESSION_SUFFIX="bzip2" ; shift
|
|
|
|
|
|
|
+ -z) COMPRESSION_ALGORITHM="-z" ; COMPRESSION_SUFFIX=".gz" ; shift
|
|
|
|
|
+ ;;
|
|
|
|
|
+ -j) COMPRESSION_ALGORITHM="-j"; COMPRESSION_SUFFIX=".bzip2" ; shift
|
|
|
;;
|
|
;;
|
|
|
-v) VERBOSE="1"; VERBOSE_OPTION="-v" ; shift
|
|
-v) VERBOSE="1"; VERBOSE_OPTION="-v" ; shift
|
|
|
;;
|
|
;;
|
|
|
|
|
+ -V) VERBOSE="1"
|
|
|
|
|
+ VERBOSE_OPTION="-v"
|
|
|
|
|
+ set -x
|
|
|
|
|
+ shift
|
|
|
|
|
+ ;;
|
|
|
-D) DEBUG="1"; shift
|
|
-D) DEBUG="1"; shift
|
|
|
;;
|
|
;;
|
|
|
-P) KEEP_PARTITIONS="1"; shift
|
|
-P) KEEP_PARTITIONS="1"; shift
|
|
@@ -123,6 +132,8 @@ while true ; do
|
|
|
esac
|
|
esac
|
|
|
done
|
|
done
|
|
|
|
|
|
|
|
|
|
+ESCAPED_COMPRESSION_SUFFIX="\$COMPRESSION_SUFFIX"
|
|
|
|
|
+
|
|
|
create_exclude_string(){
|
|
create_exclude_string(){
|
|
|
EXCLUDE_OPTION="--exclude=."
|
|
EXCLUDE_OPTION="--exclude=."
|
|
|
EXCLUDE_STRING=""
|
|
EXCLUDE_STRING=""
|
|
@@ -145,20 +156,20 @@ do_restore_disk(){
|
|
|
test "1" != "$DEBUG" && hdparm -z $DISK_DEVICE
|
|
test "1" != "$DEBUG" && hdparm -z $DISK_DEVICE
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
- ls $SOURCE_DIR/partition*.tar.$COMPRESSION_SUFFIX > /dev/null 2>&1
|
|
|
|
|
|
|
+ ls $SOURCE_DIR/partition*.tar$COMPRESSION_SUFFIX > /dev/null 2>&1
|
|
|
if [[ "$?" != "0" ]] ; then
|
|
if [[ "$?" != "0" ]] ; then
|
|
|
- echo "There are no files with the suffix .tar.$COMPRESSION_SUFFIX in directory $SOURCE_DIR"
|
|
|
|
|
|
|
+ echo "There are no files with the suffix .tar$COMPRESSION_SUFFIX in directory $SOURCE_DIR"
|
|
|
echo "Please check you are using the right compression algorithm (options could be -j -J or -z)"
|
|
echo "Please check you are using the right compression algorithm (options could be -j -J or -z)"
|
|
|
exit 6
|
|
exit 6
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
#For each partition, we restore the backup
|
|
#For each partition, we restore the backup
|
|
|
- for partition_file in $(ls $SOURCE_DIR/partition*.tar.$COMPRESSION_SUFFIX) ; do
|
|
|
|
|
- partition_dev=$(basename $partition_file | sed "s+partition-+$DISK_DEVICE+" |sed "s/\.tar\.$COMPRESSION_SUFFIX//")
|
|
|
|
|
|
|
+ for partition_file in $(ls $SOURCE_DIR/partition*.tar$COMPRESSION_SUFFIX) ; do
|
|
|
|
|
+ partition_dev=$(basename $partition_file | sed "s+partition-+$DISK_DEVICE+" |sed "s/\.tar$ESCAPED_COMPRESSION_SUFFIX//")
|
|
|
backup_basename=$(basename $partition_file)
|
|
backup_basename=$(basename $partition_file)
|
|
|
- backup_filename="$backup_basename.tar.$COMPRESSION_SUFFIX "
|
|
|
|
|
- partition_type_file=$SOURCE_DIR/$(echo $backup_basename | sed "s+\.tar\.$COMPRESSION_SUFFIX+.type+")
|
|
|
|
|
|
|
+ backup_filename="$backup_basename.tar$COMPRESSION_SUFFIX "
|
|
|
|
|
+ partition_type_file=$SOURCE_DIR/$(echo $backup_basename | sed "s+\.tar$ESCAPED_COMPRESSION_SUFFIX+.type+")
|
|
|
|
|
|
|
|
echo ""
|
|
echo ""
|
|
|
echo "--> Restoring backup $partition_file into $partition_dev"
|
|
echo "--> Restoring backup $partition_file into $partition_dev"
|
|
@@ -252,7 +263,7 @@ backup_disk(){
|
|
|
part_type_filename="$backup_basename.type"
|
|
part_type_filename="$backup_basename.type"
|
|
|
lsblk -no FSTYPE $partition_dev > $TARGET_DIR/$part_type_filename
|
|
lsblk -no FSTYPE $partition_dev > $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"
|
|
@@ -262,8 +273,8 @@ backup_disk(){
|
|
|
test "1" = "$VERBOSE" && echo "Backing up from $mountpoint_dir to $TARGET_DIR/$backup_filename"
|
|
test "1" = "$VERBOSE" && echo "Backing up from $mountpoint_dir to $TARGET_DIR/$backup_filename"
|
|
|
|
|
|
|
|
if [[ "$SKIP_TAR" != 1 ]] ; then
|
|
if [[ "$SKIP_TAR" != 1 ]] ; then
|
|
|
- test "1" = "$DEBUG" && echo "tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir ."
|
|
|
|
|
- tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir .
|
|
|
|
|
|
|
+ test "1" != "$DEBUG" && echo "tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir ."
|
|
|
|
|
+ test "1" != "$DEBUG" && tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION $EXCLUDE_STRING -pcf $TARGET_DIR/$backup_filename -C $mountpoint_dir .
|
|
|
fi
|
|
fi
|
|
|
|
|
|
|
|
umount $partition_dev
|
|
umount $partition_dev
|