]> Dogcows Code - chaz/tar/blob - scripts/restore.in
New file
[chaz/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., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
19
20 # Load library routines
21 SYSCONFDIR=${SYSCONFDIR-@sysconfdir@}
22 . ${LIBPATH-@libexecdir@}/backup.sh
23
24 usage() {
25 cat - <<EOF
26 usage: $PROGNAME [OPTIONS] [PATTERN [PATTERN...]]
27 Options are:
28
29 -l, --level=LEVEL Start restoring from backup level LEVEL (default $DUMP_LEVEL).
30 -v, --verbose[=LEVEL] Set verbosity level. Default 100.
31
32 Informational options:
33 -h, --help Display this help message.
34 -L, --license Display program license.
35 -V, --version Display program version.
36
37 Send bug reports to @PACKAGE_BUGREPORT@.
38 EOF
39 }
40
41 unset PATTERN
42 DUMP_LEVEL=0
43 CMDLINE="$0 $@"
44
45 for opt
46 do
47 if [ -z "$prev" ]; then
48 option=$opt
49 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
50 else
51 option="${prev}=$opt"
52 prev=""
53 optarg=$opt
54 fi
55 case $option in
56 --l=*|--le=*|--lev=*|--leve=*|--level=*)
57 DUMP_LEVEL=$optarg
58 ;;
59 -l|--l|--le|--lev|--leve|--level)
60 prev=$option
61 ;;
62 --verb=*|--verbo=*|--verbos=*|--verbose=*)
63 VERBOSE=$optarg
64 ;;
65 -v|--verb|--verbo|--verbos|--verbose)
66 VERBOSE=100
67 ;;
68 -v*) VERBOSE=`expr $option : "-v\(.*\)"`;;
69 -V|--v|--ve|--ver|--vers|--versi|--versio|--version)
70 echo "restore; @PACKAGE@ (@VERSION@)"
71 exit 0;;
72 -L|--li|--lic|--lice|--licen|--licens|--license)
73 license
74 exit;;
75 -h|--h|--he|--hel|--help)
76 usage
77 exit;;
78 -*) bailout "Unknown option $opt. Try $PROGNAME --help for more info.";;
79 *) if [ -z "$PATTERN" ]; then
80 PATTERN=$opt
81 else
82 PATTERN="$PATTERN|$opt"
83 fi
84 ;;
85 esac
86 done
87
88 init_restore
89 cat > $LOGFILE <<EOF
90 This file contains any messages produced by $PROGNAME.
91
92 It was created by GNU $PROGNAME, from @PACKAGE@ (@VERSION@).
93 Invocation command line was
94
95 \$ $CMDLINE
96
97 EOF
98
99 restore_fs()
100 {
101 fs="`echo \"${1}\" | sed -e 's/^.*://'`"
102 fsname="`echo \"${1}\" | sed -e 's/\//:/g'`"
103 remotehost="`expr \"${1}\" : '\([^/][^/]*\):.*'`"
104 if [ -z "$remotehost" ]; then
105 remotehost=$localhost
106 fi
107 message 10 "fs=$fs"
108 message 10 "fsname=$fsname"
109 message 10 "remotehost=$remotehost"
110
111 LOGPAT="`level_log_name ${fsname} '[0-9]'`"
112 PREFIX="`level_log_name ${fsname} ''`"
113 message 10 LOGPAT=$LOGPAT
114 message 10 PREFIX=$PREFIX
115 LEVELS=`remote_run "${remotehost}" ls $LOGPAT |
116 sed "s,$PREFIX,," | sort -n`
117 message 10 "LEVELS=$LEVELS"
118
119 echo "Starting restore of ${1} at level $DUMP_LEVEL."
120 for level in $LEVELS
121 do
122 if [ $level -lt $DUMP_LEVEL ]; then
123 message 10 "Skipping level $level"
124 continue;
125 fi
126 message 10 "Restoring level $level"
127
128 DATE=`get_dump_time $level`
129 FILE="`level_log_name ${fsname} ${level}`"
130 message 10 "FILE=$FILE"
131
132 LABEL="`print_level $level` backup of ${fs} on ${remotehost} at ${DATE}"
133 ${RESTORE_BEGIN-:} $level $remotehost $fs $fsname
134 backup_host ${remotehost} \
135 "--listed=`level_log_name $fs $level`" \
136 "--label=\"$LABEL\"" \
137 -C ${ROOT_FS-/}$fs
138 ${RESTORE_END-:} $level $remotehost $fs $fsname
139 done
140 }
141
142 restore_files()
143 {
144 LOGPAT="`level_log_name MISC '[0-9]'`"
145 PREFIX="`level_log_name MISC ''`"
146 message 10 LOGPAT=$LOGPAT
147 message 10 PREFIX=$PREFIX
148 LEVELS=`remote_run "${localhost}" ls $LOGPAT | sed "s,$PREFIX,," | sort -n`
149 message 10 "LEVELS=$LEVELS"
150
151 echo "Starting restore of miscellaneous files at level $DUMP_LEVEL."
152 for level in $LEVELS
153 do
154 if [ $level -lt $DUMP_LEVEL ]; then
155 message 10 "Skipping level $level"
156 continue;
157 fi
158 message 10 "Restoring level $level"
159
160 DATE=`get_dump_time $level`
161 FILE="`level_log_name MISC ${level}`"
162 message 10 "FILE=$FILE"
163
164 LABEL="`print_level $level` backup of miscellaneous files at ${DATE}"
165 ${RESTORE_BEGIN-:} $level $localhost MISC MISC
166 backup_host ${localhost} \
167 "--listed=`level_log_name MISC $level`" \
168 "--label=\"$LABEL\"" \
169 -C ${ROOT_FS-/} $@
170 ${RESTORE_END-:} $level $localhost MISC MISC
171 done
172 }
173
174 # Operation Overwiew:
175 #
176 # 1. Determine the time of the last backup
177 # 2. Create list of incremental listings to process
178 # 3. For each filesystem:
179 # 3.1. Start at the requested dump level (default 0) and proceed up to
180 # the last available level:
181 # 3.1.1 Deduce the volume label
182 # 3.1.2. Invoke [rsh] tar --listed=FILE --label=LABEL [opts] -xf $TAPE_FILE
183 # 4. End
184
185 (message 1 "Preparing for restore"
186
187 message 1 "processing backup directories"
188
189 for dir in ${BACKUP_DIRS}
190 do
191 message 1 "Processing $dir"
192 case $dir in
193 ${PATTERN-*}) restore_fs $dir;;
194 esac
195 done
196
197 if [ "x${BACKUP_FILES}" != "x" ] ; then
198 message 1 "processing miscellaneous files"
199 if [ -z "$PATTERN" ]; then
200 restore_files
201 else
202 RESTORE_FILES=""
203 for file in ${BACKUP_FILES}
204 do
205 rel_file=`expr $file : '/\(.*\)'`
206 case $file in
207 $PATTERN) if [ -z "$RESTORE_FILES" ]; then
208 RESTORE_FILES="$rel_file"
209 else
210 RESTORE_FILES="$RESTORE_FILES $rel_file"
211 fi;;
212 esac
213 done
214 [ -z "$RESTORE_FILES" ] || restore_files $RESTORE_FILES
215 fi
216
217 fi) 2>&1 | tee -a "${LOGFILE}"
218
219 # EOF
220
221
222
223
224
This page took 0.04939 seconds and 5 git commands to generate.