no backticks

This commit is contained in:
kneutron 2021-04-09 06:07:11 -05:00 committed by GitHub
parent 3419a1955d
commit 5b9e080b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,13 @@
#!/bin/bash #!/bin/bash
# =LLC= © (C)opyright 2017 Boojum Consulting LLC / Dave Bechtel, All rights reserved.
## NOTICE: Only Boojum Consulting LLC personnel may use or redistribute this code,
## Unless given explicit permission by the author - see http://www.boojumconsultingsa.com
#
# To be run from systemrescuecd environment; NOTE restore disk MUST be partitioned 1st! # To be run from systemrescuecd environment; NOTE restore disk MUST be partitioned 1st!
# REQUIRES 1 arg: filename of .fsa # REQUIRES 1 arg: filename of .fsa
# copy this script to /tmp and chmod +x, run from there # copy this script to /tmp and chmod +x, run from there
# NOTE ISO from mkrestoredvdiso should be mounted on 2nd dvd drive
# NOTE having a copy of supergrubdisc is handy if the VM fails to boot
# REF: https://distrowatch.com/table.php?distribution=supergrub
# TODO include /home and restore that? IF EXIST # TODO include /home and restore that? IF EXIST
# failexit.mrg # failexit.mrg
@ -16,8 +16,8 @@ function failexit () {
exit $1 exit $1
} }
# TODO editme # xxx TODO editme - assumes swap is on sda1
rootdev=/dev/sda1 # for VM rootdev=/dev/sda2 # for VM
rdevonly=${rootdev%[[:digit:]]} rdevonly=${rootdev%[[:digit:]]}
umount $rootdev # failsafe umount $rootdev # failsafe
@ -31,14 +31,14 @@ myres=BOOJUM-RESTORE.sh # injection script
# NOTE sr0 is systemrescue # NOTE sr0 is systemrescue
mount /dev/sr1 $cdr -oro mount /dev/sr1 $cdr -oro
chkmount=`df |grep -c $cdr` chkmount=$(df |grep -c $cdr)
[ $chkmount -gt 0 ] || failexit 99 "Failed to mount $cdr"; # failed to mount [ $chkmount -gt 0 ] || failexit 99 "Failed to mount $cdr"; # failed to mount
chkmount=`df |grep -c $rootdir` chkmount=$(df |grep -c $rootdir)
[ $chkmount -eq 0 ] || failexit 98 "$rootdir is still mounted - cannot restore!"; [ $chkmount -eq 0 ] || failexit 98 "$rootdir is still mounted - cannot restore!"
cd $cdr || failexit 199 "Cannot CD to $cdr"; cd $cdr || failexit 199 "Cannot CD to $cdr";
pwd pwd
echo "`date` - RESTORING root filesystem to $rootdev" echo "$(date) - RESTORING root filesystem to $rootdev"
# PROBLEM with long filenames in UDF - gets cut off, use $1 # PROBLEM with long filenames in UDF - gets cut off, use $1
#time fsarchiver restfs *.fsa id=0,dest=$rootdev #time fsarchiver restfs *.fsa id=0,dest=$rootdev
@ -65,19 +65,19 @@ mount $rootdev $rootdir -onoatime,rw
sed -i '/swap/s/^/#/' $rootdir/etc/fstab; grep swap $rootdir/etc/fstab sed -i '/swap/s/^/#/' $rootdir/etc/fstab; grep swap $rootdir/etc/fstab
# Detect swap partition(s) in restore environ - print /dev/sdXX w/o ":" # Detect swap partition(s) in restore environ - print /dev/sdXX w/o ":"
for p in `blkid |grep TYPE=\"swap\" |awk -F: '{ print $1 }'`; do for p in $(blkid |grep TYPE=\"swap\" |awk -F: '{ print $1 }'); do
pmod=${p##*/} # strip off beginning /dev/, leave sdXX pmod=${p##*/} # strip off beginning /dev/, leave sdXX
swapuuid=`ls -l /dev/disk/by-uuid |grep $pmod |awk '{ print $9 }'` swapuuid=$(ls -l /dev/disk/by-uuid |grep $pmod |awk '{ print $9 }')
# check have we already done this? # check have we already done this?
[ `grep -c $swapuuid $rootdir/etc/fstab` -gt 0 ] || \ [ $(grep -c $swapuuid $rootdir/etc/fstab) -gt 0 ] || \
echo "UUID=$swapuuid swap swap defaults,pri=2 0 0" |tee -a $rootdir/etc/fstab echo "UUID=$swapuuid swap swap defaults,pri=2 0 0" |tee -a $rootdir/etc/fstab
# echo "UUID=$swapuuid swap swap defaults,pri=2 0 0" >> $rootdir/etc/fstab # echo "UUID=$swapuuid swap swap defaults,pri=2 0 0" >> $rootdir/etc/fstab
done done
# /dev/sdb5 # /dev/sdb5
#ls -l /dev/disk/by-uuid |grep sdb5 #ls -l /dev/disk/by-uuid |grep sdb5
# 1 2 3 4 5 6 7 8 9 # 1 2 3 4 5 6 7 8 9 10 11
#lrwxrwxrwx 1 root root 10 Aug 27 11:09 dfc46f8f-bcfa-4e73-b62f-b24dd0bf60cf -> ../../sdb5 #lrwxrwxrwx 1 root root 10 Aug 27 11:09 dfc46f8f-bcfa-4e73-b62f-b24dd0bf60cf -> ../../sdb5
# Make sure we can boot! # Make sure we can boot!
@ -100,56 +100,13 @@ chroot $rootdir /bin/bash /$myres
#umount -a $rootdir/* #umount -a $rootdir/*
umount -a $rootdir/{dev,proc,sys} umount -a $rootdir/{dev,proc,sys}
umount $rootdir/* 2>/dev/null umount $rootdir/* 2>/dev/null
umount $rootdir 2>/dev/null #umount $rootdir 2>/dev/null
df -h df -hT
echo "DON'T FORGET TO COPY /home and adjust fstab for swap / home / squid BEFORE booting new drive!" echo "DON'T FORGET TO COPY /home and adjust fstab for home / squid BEFORE booting new drive!"
echo "+ also adjust etc/network/interfaces , getdrives-byid , etc/rc.local , etc/hostname , etc/hosts ," echo "+ also adjust etc/network/interfaces , getdrives-byid , etc/rc.local , etc/hostname , etc/hosts ,"
echo "+ etc/init/tty11 port (home/cloudssh/.bash_login" echo "+ etc/init/tty11 port (home/cloudssh/.bash_login"
exit; exit;
HOWTO restore:
# time fsarchiver restfs *-fsarc1.fsa id=0,dest=/dev/sdf1
Statistics for filesystem 0
* files successfully processed:....regfiles=159387, directories=25579, symlinks=49276, hardlinks=25, specials=108
* files with errors:...............regfiles=0, directories=0, symlinks=0, hardlinks=0, specials=0
real 4m26.116s
( 3.9GB )
# mount /dev/sdf1 /mnt/tmp2
# grub-install --root-directory=/mnt/tmp2 /dev/sdf
# mount -o bind /dev /mnt/tmp2/dev; mount -o bind /proc /mnt/tmp2/proc; mount -o bind /sys /mnt/tmp2/sys
# chroot /mnt/tmp2 /bin/bash
# update-grub
[[
Generating grub configuration file ...
Warning: Setting GRUB_TIMEOUT to a non-zero value when GRUB_HIDDEN_TIMEOUT is set is no longer supported.
Found linux image: /boot/vmlinuz-4.2.0-36-generic
Found initrd image: /boot/initrd.img-4.2.0-36-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
Found Ubuntu 14.04.4 LTS (14.04) on /dev/sda1
done
]]
# grub-install /dev/sdf # from chroot
^D
# umount -a /mnt/tmp2/*
# DON'T FORGET TO COPY /home and adjust fstab for swap / home / squid BEFORE booting new drive!
# also adjust etc/network/interfaces , getdrives-byid , etc/rc.local , etc/hostname , etc/hosts , etc/init/tty11 port (home/cloudssh/.bash_login)
# umount /mnt/tmp2/*
# umount /mnt/tmp2
########
2017.0827 Tested, works OK