X-NEWS: cc.usu.edu comp.unix.unixware: 21172 Relay-Version: ANU News - V6.1 08/24/93 VAX/VMS V6.1; site cc.usu.edu Path: cc.usu.edu!news.cs.utah.edu!cs.utexas.edu!swrinde!gatech!newsfeed.pitt.edu!hudson.lm.com!netline-fddi.jpl.nasa.gov!nntp.et.byu.edu!news.provo.novell.com!usg!msohnius Newsgroups: comp.unix.unixware Subject: Re: cpio vs. extended backup Message-ID: From: msohnius@novell.co.uk (Martin Sohnius) Date: Wed, 1 Mar 1995 12:21:58 GMT Sender: news@novell.co.uk References: <3j1h75$q7h@mango.aloha.com> Organization: Novell Europe X-Newsreader: TIN [version 1.2 PL2] Lines: 308 Brett Collars (brettc@aloha.com) wrote: [...] : Martin provided me with a set of scripts for doing a full recovery from tape : to a fresh disk, his scripts do all the cleanup (some stuff I didn't know had : to be done and I don't think extended backup or Perfect Backup covers either). : These are the only things I need - the tape, the distribution disks, a 3.5" disk : and a cheat sheet post-it note - to do a full recovery from ground zero. I can : even do the whole thing with a belly full of 12 Beck's. [...] Below is the current version of this, and I am glad to hear that Brett is happy with it. :-) Obviously, neither I nor Novell can take any responsibility for it, treat it as the "free and unsupported" software it is... -- +----------------------------------+ Martin Sohnius | The first rule in politics: | Novell Labs Europe | "When in a hole, stop digging." | Bracknell, England | - Denis Lord Healey | +44-1344-724031 +----------------------------------+ (I speak for myself, not for Novell or anyone else.) -------++++++++++------------+++++++++++--------------+++++++++++++ I've been able to "clone" a system from a tape backup, in a procedure which could be used for "worst case recovery" scenarios, or for the loading of fully configured identical systems (change /etc/.snum to the correct serial number in the latter case). I tested the procedure described below on a relatively simple configuration (AS 1.1.1 with TCP/IP/NFS and a couple of ptf's on a single drive with only / and /stand partitions), and restored that from scratch. Other configs might be trickier, in particular if you have large mounted file systems. I have collected most of the commands into two shell scripts, called script1 and script2. They appear below at the end of the text. Keep these scripts wherever on the system it is convenient. Generating the back-up ---------------------- You need: an empty, formatted floppy diskette suitable for Drive A. a tape drive and tape capable of holding your entire system (you can unmount user file systems, and save them separately). Copy script2 to /tmp/script2. Note that this must be a COPY, not the original (or you'll lose it after a reboot). Bring system to run-level 1 with # cd / # shutdown -g -i1 -y where is the number of seconds you are giving your users to log out. Log in as root at the console and type # init S Wait, and when asked, enter the root password. You are now in true single-user mode. Make sure the running shell is /sbin/sh: # exec /sbin/sh Make sure again that a copy of script2 resides in /tmp/script2. Mount all file systems which you want to be part of the system clone image (at least / and /stand, as well as /usr, /tmp and /var if these are separate.) Make a note of hardware configuration such as IRQs and port addresses (the /etc/.diag command may be helpful). Run script1. WARNING: there is not much error checking in my scripts. Make sure to follow instructions carefully. Ignore messages about nucamd having stopped. After shutting the system down to single user mode, it will do that sooner or later. Comments on script1: The contents of /dev are put onto floppy, because devices need to be treated differently from other files during restore. The script2 file is also put on floppy, to be available before the main restore begins. The contents of /proc and /dev/fd need not (must not!) be backed up at all. See proc(4) and fd(4) for more info. After the backup is finished, you can return the system to multiuser mode by entering CTRL-D and specifying runlevel 3 (or 2 if you are not running NFS). Restoring --------- To restore, you must somehow get the machine up and at least sort-of running with the same hardware configuration and mounted filesystems as when you did the backup. This can, e.g., be done by a partial reload of the system (choose only "Basic System" from the table of packages), or with the EBF, or by just using a corrupt, but still partly functional system. If you do a partial re-load, and your keyboard is not US-ASCII, it may be a good idea to load the European Languaage Supplement as well, or you'll have to visualise the layout of a US keyboard to use yours. Once the partial system is up and running, log in as root, and then # init 1 Log in as root again when the runlevel change is completed, then # init S Wait, and when asked, enter root password once more, to enter Single User Mode. Kill the mousemgr process. Insert the backup floppy into Drive A, and do, from the command line (careful - this stuff is important, but must be done by hand): # mkdir /newdev # ln -s /newdev /tmp/dev # cd /tmp #### important #### # cpio -icdmu < /dev/rdsk/f0t # ./script2 Then follow instructions. Comments on script2: SVR4.2's cpio command will not overwrite an existing device file or named pipe. When restoring, we want to make sure that ownership/group/permissions are correct, so we want to overwrite. Hence all pipes are first removed; and /dev is restored into /newdev via the link /tmp/dev and later moved into the place of the actual /dev. The latter part of the script updates the file privileges table to take account of the new "creation" dates of the files (i.e. the time of the restore from tape). The script uses the old data and passes them on to the filepriv command. The old privileges table is copied to a (presumably) unique file name. Final comment: I had the system back and running in less than 2 hours after doing rm -r / of about 100 MBytes of data. --------------------------- cut here ---------------------------- #!/sbin/sh # script1 of 2 cd / # create a relative file name list for /dev and # its contents, except for the contents of /dev/fd echo "Creating filelist for floppy" find ./dev -print -name fd -type d -prune > /tmp/floplist # add the absolute pathname for script2 to the list # also add the name of the tape device, just to make sure echo /tmp/script2 >> /tmp/floplist echo /dev/rmt/ctape1 >> /tmp/floplist # save all other file names except /proc/* # into a different list echo "Creating filelist for tape" find / -print | egrep -v '^/dev/|^/proc/' > /tmp/tapelist # backup to floppy the contents of /dev until echo "Insert formatted floppy into Drive A.\07" echo "Hit return to continue: \c" read dummy cd cpio -ovc < /tmp/floplist > /dev/rdsk/f0t do echo "backup failed [check write protection]\n" >&2 done echo "\nRemove the floppy, label it and keep it safe as" echo "part of the backup.\n" # backup to tape the files until echo "Insert tape into drive, and hit return: \07\c" read dummy cpio -ocv < /tmp/tapelist > /dev/rmt/ctape1 do echo "backup failed [check write protection]\n" >&2 done echo "\nRemove the tape, label it and keep it safe as" echo "part of the backup.\n" # end of script1 --------------------------- cut here ---------------------------- #!/sbin/sh # script2 of 2 [ -d /tmp/dev ] || { echo "Must be run from /tmp directory" echo "Read the notes and start restore from floppy again" exit 1 } echo "Remove diskette from Drive A.\07" echo "Hit return to continue: \c" read dummy # remove all named pipes from the system echo "\nRemoving named pipes prior to restore..." find / -type p -exec rm {} \; # restore files echo "\nInsert backup tape into drive.\07" echo "Hit return to continue: \c" read dummy echo "\nRestoring files..." ulimit unlimited cpiosuccess= cpio -icdmu < /dev/rmt/ctape1 [ $? -eq 0 ] && cpiosuccess=yes # restore device files to their proper place cd / mv /dev /dev.old mv /newdev /dev rm /tmp/dev # deal with /dev/fd specially umount /dev.old/fd 2>/dev/null mount /dev/fd /dev/fd [ "$cpiosuccess" ] && { echo "\nRemoving old device files..." rm -r /dev.old } # Fix privileges file in trusted computing base. cd /etc/security/tcb [ -f privs ] || { echo "File /etc/security/tcb/privs is missing" >&2 echo "Cannot restore privileges." >&2 exit 2 } /usr/bin/cp privs oldprivs$$ oldIFS="$IFS" IFS=: while read size chksum ctime privs file do class=`IFS="$oldIFS"; /usr/bin/expr "$privs" : '%\([^,]*\),.*'` privs=`IFS="$oldIFS"; /usr/bin/expr "$privs" : '%[^,]*,\(.*\)'` echo fixing privileges for "$file" if [ "$class" = fixed ] then /usr/sbin/filepriv -f "$privs" "$file" elif [ "$class" = inher ] then /usr/sbin/filepriv -i "$privs" "$file" fi done < oldprivs$$ /sbin/initprivs echo "\nFile privileges fixed." echo "Rebooting..." init 6 sleep 100 # wait for kill # end of script2