3 if [ -z "$1" ] || [ "$1" = "--help" ]; then
7 $0 [backup-dir] restore-mount-point
9 This is script to restore from rsnapshot-based backup.
10 It copies directory tree from backup dir to restore-mount-point
11 and updaes fstab there to have correct UUIDs of partitions mounted
12 underneath this mountpoint.
14 You have to manually create partitions and filesystems on them and mount
15 it under target mount point.
20 # only one parameter is specified it is assumed to be target. So in
21 # the current directory must be only one backup
22 for candidate in alpha.0/etc "$(echo ./*/alpha.0/etc)"; do
23 if [ -d "$candidate" ]; then
24 backup="$(dirname "$candidate")"
28 if [ -z "$backup" ]; then
29 echo "Cannot find backup directory. Please specify it explicitely" >&2
39 if [ ! -d "$backup/etc" ]||[ ! -d "$backup/home" ]||[ ! -d "$backup/usr" ]; then
40 echo "$backup doesn't look like full backup of unix filesystem"
43 if [ ! -d "$restore" ]; then
44 echo "Restore mount point $restore doesn't exists" >&2
48 mount|while read -r dev _ point _ type rest; do
51 uuid="$(blkid "$dev" --output export|grep '^UUID')"
52 targetpoint=${point#$restore}
53 [ -z "$targetpoint" ]&&targetpoint=/
54 fsline=$(printf "%s %12s %s defaults 0 0" "$uuid" "$targetpoint" "$type")
55 echo "$fsline">>"$tempf"
62 # Scan for swap partitions on the same drive
63 root="$(df "$restore" --output=source|tail -1)"
65 for part in "$drive"*; do
66 data="$(blkid "$part" --output=export)"
67 uuid=$(echo "$data"|grep "^UUID=")
68 if echo "$data"|grep -q TYPE=swap; then
69 echo "$uuid none swap sw 1 0" >> "$tempf"
72 while [ ! -e "$drive" ]; do
75 echo "Going to install boot loader on $drive"
76 #read fstab and copy out all lines which do not start with UUID
77 while read -r line; do
80 if [ -e "$tempf" ]; then
89 done < "$backup/etc/fstab" > /tmp/fstab.new
92 rsync -a "$backup/" "$restore/" || exit 1
94 cp /tmp/fstab.new "$restore/etc/fstab"
95 rm "$restore/etc/udev/rules.d"/*-persistent-net.rules
96 echo "Installing bootloader"
97 mount -t proc none "$restore/proc"
98 mount -o bind /dev "$restore/dev"
99 mount -t sysfs sys "$restore/sys"
100 chroot "$restore" update-grub
101 chroot "$restore" grub-install "$drive"
102 umount "$restore/sys"
103 umount "$restore/dev"
104 umount "$restore/proc"
106 echo "Restore completed. Please reboot"