source: npl/syn3/backup/restore @ b26e5aa

gcc484perl-5.22
Last change on this file since b26e5aa was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 4.2 KB
Line 
1#!/bin/bash
2#Restore script for Syn-3 (C)DatuX
3source /etc/backup.conf || exit 1
4source $SCRIPTDIR/backuplib || exit 1
5
6FILE=$1
7if ! [ "$FILE" ]; then
8        echo "Usage: $0 <filetorestore>"
9        echo "The file should exist on the configured backup medium in /etc/backup.conf"
10        echo "WARNING: This WILL format your $BACKUPDEV!"
11        exit 1
12fi
13
14cd /
15
16#exit if already running
17CheckRunning
18
19
20#stdout will go to logs from this point
21exec &> $LOG
22
23ulimit -n 100000
24trap terminated 2 15 1
25
26terminated()
27{
28        echo "STAT:Restore session aborted!"
29        if [ "$1" ]; then
30                echo "$1";
31        fi
32        syn3-state backup ALERT "Restore aborted! Your system is unusable right now, try restoring again."
33        exit 1
34}
35
36#devfs en udev are different, solve it this way
37vgscan --mknodes &> /dev/null
38
39echo "INFO:Restore started at `date`"
40echo "INFO:Restoring $FILE"
41syn3-state backup ALERT "Disaster restore started. Your system is unusable until the restore has completed."
42
43#############################
44echo "STAT:Preparing $BACKUPDEV"
45
46echo "INFO:Killing all services that use $BACKUPMNT"
47#shut them all down except ssh
48svc -d /service/* /service/*/log
49svc -u /service/sshd
50#force kill them all
51kill -9 `lsof -F p $BACKUPMNT|cut -c2-` &>/dev/null
52sleep 5
53
54
55#TODO: maybe we skip the whole formatting and just use a rm -rf for other modes?
56#rsync is cabable of deleting stuff itself and can continue restoring in case of an interruption
57if [ $mode != "rsync" ]; then
58        echo "INFO:Unmounting $BACKUPMNT"
59        umount $BACKUPMNT >/dev/null
60        if cat /proc/mounts |cut -f2 -d' '|grep -x $BACKUPMNT >/dev/null; then
61                echo "Cannot unmount $BACKUPMNT"
62                terminated
63        fi
64        echo "INFO:Formatting..."
65        mkfs.xfs -f $BACKUPDEV >/dev/null || terminated
66
67        echo "INFO:Mounting..."
68        mount $BACKUPMNT || terminated
69fi
70
71##################################
72echo "STAT:Restoring data"
73rm -r /var/lib/xfsdump/ &>/dev/null
74
75echo "INFO:Transferring data..."
76
77#this block should output the errors of the operation so that
78#the while loop can read them
79(
80        if [ $mode == "smb" ]; then
81                smbclient --timeout 3600 -s /dev/null --stderr -c "get $FILE -" -U "$smbuser" -W "$smbdomain" "//$smbserver/$smbshare" "$smbpasswd" | gunzip | xfsrestore -o -p 10 -F - $BACKUPMNT || terminated
82                [ "${PIPESTATUS[0]}" != "0" ] && terminated "Error while reading from fileserver."
83                exit 0
84        elif [ $mode == "tape" ]; then
85                xfsrestore -L "$FILE" -o -p 10 -F -f $TAPEDEV $BACKUPMNT || terminated
86        elif [ $mode == "usbtape" ]; then
87                xfsrestore -L "$FILE" -o -b 65536 -p 10 -F -f $TAPEDEV $BACKUPMNT || terminated
88        elif [ $mode == "rsync" ]; then
89                export PASSWD="$rsyncpasswd"
90                RSYNCSRC=`echo "$FILE" | sed 's@syn3backupmeta/syn3_.*@@'`
91                /usr/backup/sshpass rsync $RSYNC_SETTINGS --rsh "$SSHCMD" -ax --numeric-ids --progress --delete --inplace --rsync-path="rsync --fake-super" "$rsyncserver:$RSYNCSRC" $BACKUPMNT/ || terminated
92        else
93                echo "Backupmode $mode is unknown!";
94                terminated
95        fi
96) 2>&1 |
97#analyse the output of the above block
98while read LINE; do
99        ProcXfsOutput "$LINE" || terminated
100done
101
102#something went wrong?
103if [ "${PIPESTATUS[0]}${PIPESTATUS[1]}" != "00" ]; then
104        exit 1
105fi
106
107##################################
108###### create special files to let the restore-magic happend during reboot:
109#Look at: http://open.syn3.nl/syn3/trac/default/wiki/SynBackup for technical details.
110
111#we have a systembackup to restore?
112if [ -e $BACKUPMNT/.syn3systembackup ]; then
113        #touch this file so the initrd will format / and /boot and copy the data there.
114        touch /boot/.syn3restoresystem
115        #for reduncany: make sure the system knows the data is consistent and the node is primary
116        touch $BACKUPMNT/.syn3systembackup/boot/drbd.primary
117        #make sure the post restore runs after restoring the system files
118        chmod +x $BACKUPMNT/.syn3systembackup/etc/postinst.d/post.restore
119else
120        #make sure the restore postinstaller runs
121        chmod +x /etc/postinst.d/post.restore
122fi
123
124#inicate we want the post.restore to run the restore-scripts
125mkdir -p "$SPOOLDIR" 2>/dev/null
126touch "$SPOOLDIR/.syn3restorespool" 2>/dev/null
127
128sync #in case they wanna use reset ;)
129
130echo "INFO:Data reading finshed at `date`"
131echo "STAT:Data reading complete, please reboot to finish restore."
132
133syn3-state backup ALERT "Please reboot the system and wait for the disaster recovery to finish."
Note: See TracBrowser for help on using the repository browser.