Quellcode durchsuchen

Added: very verbose mode, no-compresssion mode

Laurent HUBERT vor 8 Jahren
Ursprung
Commit
3a0a45d808
1 geänderte Dateien mit 24 neuen und 13 gelöschten Zeilen
  1. 24 13
      devel/diskimg

+ 24 - 13
devel/diskimg

@@ -47,6 +47,7 @@ OPTIONS:
 	-c	creates the backup using the given TARGET_DIR value
 	-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)
+	-u	uncompressed image (disables compression)
 	-z	uses gzip compression
 	-j	uses bzip2 compression
 	-P	keep existing partitions
@@ -54,6 +55,7 @@ OPTIONS:
 	-J	uses XZ compression (DEFAULT)
 	-T	skip tar archive creation (useful if backup only partition layout)
 	-v	Verbose
+	-v	Very verbose (debug mode)
 	-D	dry run
 	
 EXAMPLES:
@@ -72,7 +74,7 @@ EOF
 exit 0
 }
 
-OPTS=$(getopt c:d:e:DhjJPr:Tvz $*)
+OPTS=$(getopt c:d:e:DhjJPr:uTvVz $*)
 #Test les paramètres
 if [ $? != 0 ]
 then
@@ -87,7 +89,7 @@ DISK_DEVICE=""
 TARGET_DIR=""
 SOURCE_DIR=""
 COMPRESSION_ALGORITHM="-J"
-COMPRESSION_SUFFIX="xz"
+COMPRESSION_SUFFIX=".xz"
 VERBOSE_OPTION=""
 EXCLUDE_PATTERNS=""
 KEEP_PARTITIONS=""
@@ -102,12 +104,19 @@ while true ; do
         	;;
         -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"
+        	set -x
+        	shift
+        	;;
         -D) DEBUG="1"; shift
         	;;
         -P) KEEP_PARTITIONS="1"; shift
@@ -123,6 +132,8 @@ while true ; do
     esac
 done
 
+ESCAPED_COMPRESSION_SUFFIX="\$COMPRESSION_SUFFIX"
+
 create_exclude_string(){
 	EXCLUDE_OPTION="--exclude=."
 	EXCLUDE_STRING=""
@@ -145,20 +156,20 @@ do_restore_disk(){
 		test "1" != "$DEBUG" && hdparm -z $DISK_DEVICE
 	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
-		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)"
 		exit 6
 	fi
 	
 	
 	#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_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 "--> Restoring backup $partition_file into $partition_dev"
@@ -252,7 +263,7 @@ backup_disk(){
 			part_type_filename="$backup_basename.type"
 			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"
 			mount_dir_name="diskimg-$backup_basename"
 			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"
 			
 			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
 			
 			umount $partition_dev