So far, after dozens of syncs, it's been working perfectly.
Here is the update script:
sync.sh:
Code: Select all
#!/bin/sh
set -ep
if [ ! "$(mount | grep 'none on / type tmpfs')" ] && [ ! "$2" = "/dev/sda3" ]; then
echo "You cannot backup $2 onto itself. Exiting."
exit
fi
sudo mkdir -p /mnt
if [ "$(mount | grep ^$2)" ]; then
echo "\n$2 already mounted.\nUnmounting..."
sudo umount "$2"
fi
echo "\nMounting $2 to /mnt...\n"
sudo mount "$2" /mnt
sudo rsync --dry-run -av --delete --exclude /proc/ --exclude /media/ --exclude /tmp/ --exclude /mnt/ --exclude /dev/ --exclude /sys/ --exclude /run/ --exclude .cache/ "$1" /mnt"$1" | less
if [ "$3" = "-s" ]; then
t=5; while [ $t -gt 0 ]; do echo -ne "\rBacking up in $t seconds..."; t=$(( t - 1 )); sleep 1; done
echo "\nRunning rsync...\n"
sudo rsync -av --delete --exclude /proc/ --exclude /media/ --exclude /tmp/ --exclude /mnt/ --exclude /dev/ --exclude /sys/ --exclude /run/ --exclude .cache/ "$1" /mnt"$1"
echo "\nRunning sync..."
sync
fi
echo "\nUnmounting $2..."
sudo umount "$2"
echo "\nFinished without errors.\nYou may remove the USB stick.\n\nPress any key to exit."
bash -c 'read -n 1'
It is run as (where /dev/sda1) is the target device:
I got the backup partition working, so the entire system can be synced to the backup partition using this above script, within a matter of seconds or minutes. Getting everything working involved in me messing up the OS several times, but the secondary backup partition allowed for easy restoration of the primary system. I then cloned the entire USB, in the event that I borked the entire first USB.
The breakdown of the 30G USB is as follows:
1G GPT partition to boot on UEFI (though the system can also boot in legacy)
8G ext4 partition for /root and /home files together
8G ext4 partition, which is a clone of the first ext4 partition and used as a backup
8G ext4 partition for media (music, videos, large documents....) will not be loaded in ram
4G swap partition for suspend, hibernate, hybrid-sleep... this works in either ram boot or regular persistent boot
Whole thing works like a charm, and I've been watching videos on it, writhing this post on it, and using it as my main system. It's used on both my stationary computer and my laptop, as the kernel is the non-targeted sort. Non-free firmware packages have been installed to allow for booting from just about any machine.
It's basically a computer in a pocket.