]> git.gag.com Git - debian/tar/blob - scripts/restore.in
Update FSF postal mail address.
[debian/tar] / scripts / restore.in
1 #! /bin/sh
2 # This program is part of GNU tar
3 # Copyright 2004, Free Software Foundation
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 1, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 # 02110-1301, USA.
19
20 # Load library routines
21 SYSCONFDIR=${SYSCONFDIR-@sysconfdir@}
22 . ${LIBDIR-@libexecdir@}/backup.sh
23
24 usage() {
25         cat - <<EOF
26 usage: $PROGNAME [OPTIONS] [PATTERN [PATTERN...]]
27 Options are:
28
29    -a, --all               Restore all filesystems.
30    -l, --level=LEVEL       Start restoring from the given backup LEVEL
31                            (default $DUMP_LEVEL).
32    -v, --verbose[=LEVEL]   Set verbosity level. Default 100.
33
34 Informational options:   
35    -h, --help              Display this help message.
36    -L, --license           Display program license.
37    -V, --version           Display program version.
38
39 Send bug reports to @PACKAGE_BUGREPORT@.
40 EOF
41 }
42
43 unset PATTERN
44 DUMP_LEVEL=0
45 CMDLINE="$0 $@"
46
47 for opt
48 do
49   if [ -z "$prev" ]; then
50       option=$opt
51       optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
52   else
53       option="${prev}=$opt"
54       prev=""
55       optarg=$opt
56   fi
57   case $option in
58   -a|--a|--al|--all)
59          RESTORE_ALL=1
60          ;;
61   --l=*|--le=*|--lev=*|--leve=*|--level=*)
62          DUMP_LEVEL=$optarg
63          ;;
64   -l|--l|--le|--lev|--leve|--level)
65          prev=$option
66          ;;
67   --verb=*|--verbo=*|--verbos=*|--verbose=*)
68          VERBOSE=$optarg
69          ;;
70   -v|--verb|--verbo|--verbos|--verbose)
71          VERBOSE=100
72          ;;
73   -v*)   VERBOSE=`expr $option : "-v\(.*\)"`;;
74   -V|--v|--ve|--ver|--vers|--versi|--versio|--version)
75          echo "restore (@PACKAGE@ @VERSION@)"
76          exit 0;;
77   -L|--li|--lic|--lice|--licen|--licens|--license)
78          license
79          exit;;
80   -h|--h|--he|--hel|--help)
81          usage
82          exit;;
83   -*) bailout "Unknown option $opt. Try $PROGNAME --help for more info.";;
84   *)  if [ -z "$PATTERN" ]; then
85          PATTERN=$opt
86       else  
87          PATTERN="$PATTERN|$opt"
88       fi
89       ;;
90   esac  
91 done    
92
93 if [ -z "$RESTORE_ALL" ]; then
94         if [ -z "$PATTERN" ]; then
95                 usage
96                 exit;
97         fi
98 fi      
99
100 init_restore
101 cat > $LOGFILE <<EOF
102 This file contains any messages produced by $PROGNAME.
103
104 It was created by GNU $PROGNAME, from  @PACKAGE@ (@VERSION@).
105 Invocation command line was
106
107   \$ $CMDLINE
108   
109 EOF
110
111 restore_fs()
112 {
113     fs="`echo \"${1}\" | sed -e 's/^.*://'`"
114     fs=`root_fs $fs`
115     fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"
116     remotehost="`expr \"${1}\" : '\([^/][^/]*\):.*'`"
117     if [ -z "$remotehost" ]; then
118         remotehost=$localhost
119     fi
120     message 10 "fs=$fs"
121     message 10 "fsname=$fsname"
122     message 10 "remotehost=$remotehost"
123
124     LOGPAT="`level_log_name ${fsname} '[0-9]'`"
125     PREFIX="`level_log_name ${fsname} ''`"
126     message 10 LOGPAT=$LOGPAT
127     message 10 PREFIX=$PREFIX
128     LEVELS=`remote_run "${remotehost}" ls $LOGPAT |
129       sed "s,$PREFIX,," | sort -n`
130     message 10 "LEVELS=$LEVELS"
131
132     echo "Starting restore of ${1} at level $DUMP_LEVEL."
133     for level in $LEVELS
134     do
135       if [ $level -lt $DUMP_LEVEL ]; then
136           message 10 "Skipping level $level"
137           continue;
138       fi
139       message 10 "Restoring level $level"
140
141       DATE=`get_dump_time $level`
142       FILE="`level_log_name ${fsname} ${level}`"
143       message 10 "FILE=$FILE"
144       
145       LABEL="`print_level $level` backup of ${fs} on ${remotehost} at ${DATE}"
146       ${RESTORE_BEGIN-:} $level $remotehost $fs $fsname
147       backup_host ${remotehost} \
148                   "--listed=\"$FILE\"" \
149                   "--label=\"$LABEL\"" \
150                   -C $fs
151       ${RESTORE_END-:} $level $remotehost $fs $fsname             
152     done
153 }
154
155 restore_files()
156 {
157     LOGPAT="`level_log_name MISC '[0-9]'`"
158     PREFIX="`level_log_name MISC ''`"
159     message 10 LOGPAT=$LOGPAT
160     message 10 PREFIX=$PREFIX
161     LEVELS=`remote_run "${localhost}" ls $LOGPAT | sed "s,$PREFIX,," | sort -n`
162     message 10 "LEVELS=$LEVELS"
163
164     echo "Starting restore of miscellaneous files at level $DUMP_LEVEL."
165     for level in $LEVELS
166     do
167       if [ $level -lt $DUMP_LEVEL ]; then
168           message 10 "Skipping level $level"
169           continue;
170       fi
171       message 10 "Restoring level $level"
172       
173       DATE=`get_dump_time $level`
174       FILE="`level_log_name MISC ${level}`"
175       message 10 "FILE=$FILE"
176       
177       LABEL="`print_level $level` backup of miscellaneous files at ${DATE}"
178       ${RESTORE_BEGIN-:} $level $localhost MISC MISC
179       backup_host ${localhost} \
180                   "--listed=\"$FILE\"" \
181                   "--label=\"$LABEL\"" \
182                   -C ${ROOT_FS-/} $@
183       ${RESTORE_END-:} $level $localhost MISC MISC
184     done
185 }
186
187 # Operation Overwiew:
188 #
189 # 1. Determine the time of the last backup
190 # 2. Create list of incremental listings to process
191 # 3. For each filesystem:
192 #  3.1. Start at the requested dump level (default 0) and proceed up to
193 #       the last available level:
194 #   3.1.1 Deduce the volume label
195 #   3.1.2. Invoke [rsh] tar --listed=FILE --label=LABEL [opts] -xf $TAPE_FILE
196 # 4. End
197
198 (message 1 "Preparing for restore"
199
200 message 1 "processing backup directories"
201
202 for dir in ${BACKUP_DIRS}
203 do
204     message 1 "Processing $dir"
205     case $dir in
206         ${PATTERN-*}) restore_fs $dir;;
207     esac
208 done
209
210 if [ "x${BACKUP_FILES}" != "x" ] ; then
211     message 1 "processing miscellaneous files"
212     if [ -z "$PATTERN" ]; then
213         restore_files
214     else
215         RESTORE_FILES=""
216         for file in ${BACKUP_FILES}
217         do
218           rel_file=`expr $file : '/\(.*\)'`
219           case $file in
220               $PATTERN) if [ -z "$RESTORE_FILES" ]; then
221                            RESTORE_FILES="$rel_file"
222                         else
223                            RESTORE_FILES="$RESTORE_FILES $rel_file"
224                         fi;;
225           esac
226         done
227         [ -z "$RESTORE_FILES" ] || restore_files $RESTORE_FILES
228     fi
229         
230 fi) 2>&1 | tee -a "${LOGFILE}"
231
232 # EOF    
233
234     
235     
236           
237