Files
RescueBRU/customcd/files/root/rescuebru/clone.sh
2026-03-03 19:53:38 -05:00

49 lines
1.4 KiB
Bash

#!/bin/bash
# clone.sh
# Rescue CD Backup & Restore Utility drive/partition cloning utility
# version 7.2.5
# Rod Wright 1/19/2024
# Refer to CHANGELOG file for details.
# -----------------------------------------------------------------------------
PROG_NAME="clone.sh"
PROG_VERSION=7.2.5
PROG_REVISION=1
RBRU_INSTALL_PATH="/root/rescuebru"
source $RBRU_INSTALL_PATH/functions.sh
# test for required arguments
if [ "$#" -ne 2 ]; then
echo "clone.sh: Invalid number of arguments."
echo "Usage: clone <source> <destination>"
echo "source and destination can be drives (/dev/sda) or partitions"
echo "(/dev/sda1)."
echo "Please ensure the size of the destination is equal to or"
echo "greater than the size of the source."
exit 1
fi
source_dev=$1
dest_dev=$2
dd_bs=4096
# determine sizes of devices
source_size=`blockdev --getsize64 $source_dev`
dest_size=`blockdev --getsize64 $dest_dev`
# compare sizes and warn if necessary
if [ $dest_size -lt $source_size ]; then
pv_size=$dest_size
if ! approved "WARNING: The size of the destination device seems to be smaller than the size of the source device. Continue anyway?" ; then
inform "Aborting" "3"
exit 1
fi
else
pv_size=$source_size
fi
# now do the clone
monitor "dd if=$source_dev bs=$dd_bs conv=sync,noerror status=noxfer|pv -s $pv_size|dd of=$dest_dev bs=$dd_bs" "pausable"
exit $?