Add 'samback.sh'

This commit is contained in:
nodemixaholic 2024-02-24 00:17:45 +00:00
parent a0a7f4c6e9
commit 3f9a7996fb

33
samback.sh Normal file
View file

@ -0,0 +1,33 @@
#!/bin/bash
# Neat splash.
echo ""
echo " mmmm mmmmm m "
echo " mm mmm mmm m m mmm mmm m m "
echo " mmmmm m m m m m mmmmm m m m m m mm "
echo " mm mmmmm m m m m m mmmmm m mmm "
echo " mmmmm m m m m mmmmmm m mmmm m mm "
echo " THE Simple Cloning Automated Tool, MAN!"
echo " Version 2.2024a"
# Get the currently booted HDD
root_device=$(df / | grep -Eo '^/dev/[^[:space:]]+')
# Extract the HDD from the root device
booted_hdd=$(echo "$root_device" | sed 's/[0-9]*$//' | sed 's/\/dev\///g')
# Find first other connected HDD of same size
other_hdd=$(lsblk -o NAME,SIZE -d | grep "$(lsblk -o SIZE -n /dev/$booted_hdd | head -n 1)"| grep -v "$booted_hdd" | awk '{print $1}' | head -n 1)
echo "<SAMBACK> [MSG]: Currently booted HDD (from): $booted_hdd"
echo "<SAMBACK> [MSG]: Same size HDD that is NOT the currently booted device (to): $other_hdd"
if [ ! "$other_hdd" == "" ]; then
# Here we clone our boot drive to our other drive
echo "<SAMBACK> [MSG]: Cloning booted /dev/$booted_hdd to /dev/$other_hdd... (This may take awhile, will run in background)"
sudo nohup dd if=/dev/$booted_hdd of=/dev/$other_hdd bs=4M status=progress > /dev/null 2>&1 &
else
echo "<SAMBACK> [ERR]: No drive of same size as boot device found!"
exit 1
fi