Created
September 22, 2018 00:03
-
-
Save eikenb/1f7fe01ea60a9f907a34cb6186a4e438 to your computer and use it in GitHub Desktop.
My script to make a bootable mirror of my laptop drive.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
if [ $(id -u) -ne 0 ] | |
then | |
echo "Rerunning with sudo..." | |
fullpath="$(readlink -f $0)" | |
exec sudo $fullpath | |
fi | |
while true; do | |
cat /proc/mounts | grep mirror && break | |
sleep 1 | |
done | |
ROOT=/media/data/mirror | |
/usr/bin/rsync -vPaxSHAX --delete --numeric-ids \ | |
/ /media/data/mirror | |
#--exclude media/automnt/usb/ \ | |
# include external disk if plugged in | |
if [ -d /media/automnt/usb/home ]; then | |
/usr/bin/rsync -vPaxSHAX --delete --numeric-ids \ | |
/media/automnt/usb/ /media/data/mirror/media/automnt/usb | |
fi | |
# NOTE for disk move | |
# Mount from rescue disk | |
# Make filesystem | |
#mkfs.ext4 /mnt/new | |
# Sync data | |
#/usr/bin/rsync -PaxSHAX --delete --numeric-ids /mnt/old/ /mnt/new | |
# Then do the below, except without the fstab change. | |
### Make backup bootable | |
# change to use the mirror disk | |
sed -i -e 's/LABEL=root/LABEL=mirror/' ${ROOT}/etc/fstab | |
# required mounts | |
for fs in dev dev/pts sys proc ; do | |
mount -o bind /${fs} ${ROOT}/${fs} | |
done | |
# dpkg-reconfigure is only needed if you need to run grub-install | |
#sudo chroot ${ROOT} dpkg-reconfigure grub-pc | |
chroot ${ROOT} update-grub | |
chroot ${ROOT} update-initramfs -u -k all | |
for fs in sys proc dev/pts dev ; do | |
umount ${ROOT}/${fs} | |
done | |
# done | |
umount -v /media/data/mirror |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment