|
@@ -149,13 +149,37 @@ log_debug(){
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+prepare_btrfs_subvols(){
|
|
|
|
|
+ local target_btrfs_dev=$1
|
|
|
|
|
+
|
|
|
|
|
+ local temp_mount_point=$(mktemp -d)
|
|
|
|
|
+
|
|
|
|
|
+ mount $target_btrfs_dev $temp_mount_point
|
|
|
|
|
+ mkdir $temp_mount_point/.snapshots
|
|
|
|
|
+ btrfs sub snap $temp_mount_point/ $temp_mount_point/.snapshots/ACTIVE
|
|
|
|
|
+ #Gets the active sub snapshot id:
|
|
|
|
|
+ local snap_id=$(btrfs sub list $temp_mount_point |grep '.snapshots/ACTIVE' | awk '{print $2}')
|
|
|
|
|
+
|
|
|
|
|
+ #Sets it at the current snap
|
|
|
|
|
+ btrfs sub set $snap_id $temp_mount_point
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
format_partition(){
|
|
format_partition(){
|
|
|
local partition_type="$1"
|
|
local partition_type="$1"
|
|
|
local target_device="$2"
|
|
local target_device="$2"
|
|
|
echo "Formating $target_device with type $partition_type"
|
|
echo "Formating $target_device with type $partition_type"
|
|
|
|
|
+
|
|
|
if [[ "1" != "$DEBUG" ]] ; then
|
|
if [[ "1" != "$DEBUG" ]] ; then
|
|
|
- mkfs -t $partition_type $target_device
|
|
|
|
|
- test "$?" == 0 || exit $?
|
|
|
|
|
|
|
+ case $partition_type in
|
|
|
|
|
+ btrfs) mkfs.btrfs -f -L $partition_type $target_device
|
|
|
|
|
+ test "$?" == 0 || exit $?
|
|
|
|
|
+ prepare_btrfs_subvols $target_device
|
|
|
|
|
+ ;;
|
|
|
|
|
+ *)
|
|
|
|
|
+ mkfs -t $partition_type $target_device
|
|
|
|
|
+ test "$?" == 0 || exit $?
|
|
|
|
|
+ ;;
|
|
|
|
|
+ esac
|
|
|
fi
|
|
fi
|
|
|
_REAL_TARGET_DEVICE=$target_device
|
|
_REAL_TARGET_DEVICE=$target_device
|
|
|
}
|
|
}
|
|
@@ -166,30 +190,35 @@ create_luks_container(){
|
|
|
echo "Creating a new LUKS container"
|
|
echo "Creating a new LUKS container"
|
|
|
if [ "$DEBUG" != "1" ] && [ "$FAKE_DEVICE" != "1" ] ; then
|
|
if [ "$DEBUG" != "1" ] && [ "$FAKE_DEVICE" != "1" ] ; then
|
|
|
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 $target_device <<EOF
|
|
cryptsetup luksFormat -c aes-xts-plain64 -s 512 -h sha512 $target_device <<EOF
|
|
|
-YES
|
|
|
|
|
-MOT_DE_PASSE
|
|
|
|
|
|
|
+$_luks_password
|
|
|
EOF
|
|
EOF
|
|
|
fi
|
|
fi
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
prepare_partition(){
|
|
prepare_partition(){
|
|
|
local partition_type="$1"
|
|
local partition_type="$1"
|
|
|
- local target_device="$2"
|
|
|
|
|
|
|
+ local the_target_device="$2"
|
|
|
local backup_basename=$3
|
|
local backup_basename=$3
|
|
|
|
|
+ log_debug "partition_type=$partition_type"
|
|
|
|
|
+
|
|
|
for part_type in $(echo $partition_type) ; do
|
|
for part_type in $(echo $partition_type) ; do
|
|
|
|
|
+ log_debug "part_type=$part_type"
|
|
|
|
|
+ log_debug "the_target_device=$the_target_device"
|
|
|
|
|
+
|
|
|
case $part_type in
|
|
case $part_type in
|
|
|
crypto_LUKS)
|
|
crypto_LUKS)
|
|
|
- ask_password $target_device
|
|
|
|
|
- create_luks_container $target_device
|
|
|
|
|
- open_luks_container $target_device $backup_basename
|
|
|
|
|
|
|
+ ask_password $the_target_device
|
|
|
|
|
+ create_luks_container $the_target_device
|
|
|
|
|
+ open_luks_container $the_target_device $backup_basename
|
|
|
#Now that the partition is opened, we will format it at next loop:
|
|
#Now that the partition is opened, we will format it at next loop:
|
|
|
- target_device=$_UNCRYPTED_DEVICE
|
|
|
|
|
|
|
+ the_target_device=$_UNCRYPTED_DEVICE
|
|
|
;;
|
|
;;
|
|
|
*)
|
|
*)
|
|
|
- format_partition $part_type $target_device
|
|
|
|
|
|
|
+ format_partition $part_type $the_target_device
|
|
|
;;
|
|
;;
|
|
|
esac
|
|
esac
|
|
|
done
|
|
done
|
|
|
|
|
+ _REAL_FILESYSTEM_TYPE=$part_type
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
restore_partition(){
|
|
restore_partition(){
|
|
@@ -211,7 +240,9 @@ restore_partition(){
|
|
|
if [[ "$SKIP_TAR" != 1 ]] ; then
|
|
if [[ "$SKIP_TAR" != 1 ]] ; then
|
|
|
if [[ "1" = "$DEBUG" ]] ; then
|
|
if [[ "1" = "$DEBUG" ]] ; then
|
|
|
echo tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION -pxf $partition_file -C $mountpoint_dir
|
|
echo tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION -pxf $partition_file -C $mountpoint_dir
|
|
|
- if [[ "$FAKE_DEVICE" != "1" ]] ; then
|
|
|
|
|
|
|
+ fi
|
|
|
|
|
+ if [[ "$FAKE_DEVICE" != "1" ]] ; then
|
|
|
|
|
+ if [[ "1" != "$DEBUG" ]] ; then
|
|
|
tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION -pxf $partition_file -C $mountpoint_dir
|
|
tar --numeric-owner $COMPRESSION_ALGORITHM $VERBOSE_OPTION -pxf $partition_file -C $mountpoint_dir
|
|
|
test "$?" == 0 || exit $?
|
|
test "$?" == 0 || exit $?
|
|
|
fi
|
|
fi
|
|
@@ -261,12 +292,6 @@ do_restore_disk(){
|
|
|
backup_filename="$backup_basename.tar$COMPRESSION_SUFFIX "
|
|
backup_filename="$backup_basename.tar$COMPRESSION_SUFFIX "
|
|
|
partition_type_file=$SOURCE_DIR/$backup_basename.type
|
|
partition_type_file=$SOURCE_DIR/$backup_basename.type
|
|
|
|
|
|
|
|
- log_debug "+++ partition_dev =$partition_dev"
|
|
|
|
|
- log_debug "+++ backup_basename =$backup_basename"
|
|
|
|
|
- log_debug "+++ backup_filename =$backup_filename"
|
|
|
|
|
- log_debug "+++ partition_type_file=$partition_type_file"
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
echo "--- Preparing backup restoration of $partition_file into $partition_dev ---"
|
|
echo "--- Preparing backup restoration of $partition_file into $partition_dev ---"
|
|
|
|
|
|
|
|
if [[ "$KEEP_PARTITIONS" != "1" ]] ; then
|
|
if [[ "$KEEP_PARTITIONS" != "1" ]] ; then
|
|
@@ -327,8 +352,19 @@ backup_mounted_volume(){
|
|
|
|
|
|
|
|
ask_password(){
|
|
ask_password(){
|
|
|
local partition_dev=$1
|
|
local partition_dev=$1
|
|
|
- echo "Enter encrypted partition passphrase for $partition_dev:"
|
|
|
|
|
- read -s _luks_password
|
|
|
|
|
|
|
+ local second_try="FAKE"
|
|
|
|
|
+ while [[ "$second_try" != "$_luks_password" ]] ; do
|
|
|
|
|
+ echo "Enter encrypted partition passphrase for $partition_dev:"
|
|
|
|
|
+ read -s _luks_password
|
|
|
|
|
+
|
|
|
|
|
+ echo "Please confirm passphrase:"
|
|
|
|
|
+ read -s second_try
|
|
|
|
|
+
|
|
|
|
|
+ if [[ "$second_try" != "$_luks_password" ]] ; then
|
|
|
|
|
+ echo "ERROR: passphrases do not match"
|
|
|
|
|
+ fi
|
|
|
|
|
+ done
|
|
|
|
|
+ _luks_password=$second_try
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
open_luks_container(){
|
|
open_luks_container(){
|