2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: sendbackup-dump.c,v 1.90 2006/07/25 18:10:07 martinea Exp $
29 * send backup data using BSD dump
33 #include "sendbackup.h"
38 #define LEAF_AND_DIRS "sed -e \'\ns/^leaf[ \t]*[0-9]*[ \t]*\\.//\nt\n/^dir[ \t]/ {\ns/^dir[ \t]*[0-9]*[ \t]*\\.//\ns%$%/%\nt\n}\nd\n\'"
40 static amregex_t re_table[] = {
41 /* the various encodings of dump size */
42 /* this should also match BSDI pre-3.0's buggy dump program, that
43 produced doubled DUMP: DUMP: messages */
44 AM_SIZE_RE("DUMP: [0-9][0-9]* tape blocks", 1024),
45 AM_SIZE_RE("dump: Actual: [0-9][0-9]* tape blocks", 1024),
46 AM_SIZE_RE("backup: There are [0-9][0-9]* tape blocks on [0-9][0-9]* tapes",
48 AM_SIZE_RE("backup: [0-9][0-9]* tape blocks on [0-9][0-9]* tape\\(s\\)",
50 AM_SIZE_RE("backup: [0-9][0-9]* 1k blocks on [0-9][0-9]* volume\\(s\\)",
52 AM_SIZE_RE("DUMP: [0-9][0-9]* blocks \\([0-9][0-9]*KB\\) on [0-9][0-9]* volume",
54 AM_SIZE_RE("DUMP: [0-9][0-9]* blocks \\([0-9][0-9]*\\.[0-9][0-9]*MB\\) on [0-9][0-9]* volume",
56 AM_SIZE_RE("DUMP: [0-9][0-9]* blocks", 512),
57 AM_SIZE_RE("DUMP: [0-9][0-9]* bytes were dumped", 1),
59 AM_SIZE_RE("vdump: Dumped [0-9][0-9]* of [0-9][0-9]* bytes", 1),
61 AM_SIZE_RE("dump: Actual: [0-9][0-9]* blocks output to pipe", 1024),
63 AM_SIZE_RE("dump: Dumped [0-9][0-9]* of [0-9][0-9]* bytes", 1),
65 AM_SIZE_RE("DUMP: [0-9][0-9]* KB actual output", 1024),
66 /* HPUX 10.20 and above vxdump */
67 AM_SIZE_RE("vxdump: [0-9][0-9]* tape blocks", 1024),
69 AM_SIZE_RE("vxdump: [0-9][0-9]* blocks", 1024),
71 AM_SIZE_RE(" VXDUMP: [0-9][0-9]* blocks", 512),
73 AM_SIZE_RE(" UFSDUMP: [0-9][0-9]* blocks", 512),
74 /* Irix 6.2 xfs dump */
75 AM_SIZE_RE("xfsdump: media file size [0-9][0-9]* bytes", 1),
77 AM_SIZE_RE("DUMP: [0-9][0-9]* KB", 1024),
79 /* strange dump lines */
80 AM_STRANGE_RE("should not happen"),
81 AM_STRANGE_RE("Cannot open"),
82 AM_STRANGE_RE("[Ee]rror"),
83 AM_STRANGE_RE("[Ff]ail"),
84 /* XXX add more ERROR entries here by scanning dump sources? */
86 /* any blank or non-strange DUMP: lines are marked as normal */
87 AM_NORMAL_RE("^ *DUMP:"),
88 AM_NORMAL_RE("^dump:"), /* OSF/1 */
89 AM_NORMAL_RE("^vdump:"), /* OSF/1 */
90 AM_NORMAL_RE("^ *vxdump:"), /* HPUX10 */
91 AM_NORMAL_RE("^ *vxfs *vxdump:"), /* Solaris */
92 AM_NORMAL_RE("^Dumping .* to stdout"), /* Sol vxdump */
93 AM_NORMAL_RE("^xfsdump:"), /* IRIX xfs */
94 AM_NORMAL_RE("^ *VXDUMP:"), /* Sinix */
95 AM_NORMAL_RE("^ *UFSDUMP:"), /* Sinix */
97 #ifdef VDUMP /* this is for OSF/1 3.2's vdump for advfs */
98 AM_NORMAL_RE("^The -s option is ignored"), /* OSF/1 */
99 AM_NORMAL_RE("^path"), /* OSF/1 */
100 AM_NORMAL_RE("^dev/fset"), /* OSF/1 */
101 AM_NORMAL_RE("^type"), /* OSF/1 */
102 AM_NORMAL_RE("^advfs id"), /* OSF/1 */
103 AM_NORMAL_RE("^[A-Z][a-z][a-z] [A-Z][a-z][a-z] .[0-9] [0-9]"), /* OSF/1 */
106 AM_NORMAL_RE("^backup:"), /* AIX */
107 AM_NORMAL_RE("^ Use the umount command to unmount the filesystem"),
109 AM_NORMAL_RE("^[ \t]*$"),
111 /* catch-all; DMP_STRANGE is returned for all other lines */
115 static void start_backup(char *host, char *disk, char *amdevice, int level,
116 char *dumpdate, int dataf, int mesgf, int indexf);
117 static void end_backup(int status);
120 * doing similar to $ dump | compression | encryption
134 int dumpin, dumpout, compout;
135 char *dumpkeys = NULL;
139 char *indexcmd = NULL;
140 char level_str[NUM_STR_SIZE];
141 char *compopt = NULL;
142 char *encryptopt = skip_argument;
146 (void)dumpdate; /* Quiet unused parameter warning */
148 snprintf(level_str, SIZEOF(level_str), "%d", level);
150 qdisk = quote_string(disk);
151 dbprintf(("%s: start: %s:%s lev %d\n",
152 get_pname(), host, qdisk, level));
154 fprintf(stderr, "%s: start [%s:%s level %d]\n",
155 get_pname(), host, qdisk, level);
158 /* apply client-side encryption here */
159 if ( options->encrypt == ENCRYPT_CUST ) {
160 encpid = pipespawn(options->clnt_encrypt, STDIN_PIPE,
161 &compout, &dataf, &mesgf,
162 options->clnt_encrypt, encryptopt, NULL);
163 dbprintf(("%s: pid %ld: %s\n",
164 debug_prefix_time("-gnutar"), (long)encpid, options->clnt_encrypt));
169 /* now do the client-side compression */
172 if(options->compress == COMPR_FAST || options->compress == COMPR_BEST) {
173 compopt = skip_argument;
175 #if defined(COMPRESS_BEST_OPT) && defined(COMPRESS_FAST_OPT)
176 if(options->compress == COMPR_BEST) {
177 compopt = COMPRESS_BEST_OPT;
179 compopt = COMPRESS_FAST_OPT;
182 comppid = pipespawn(COMPRESS_PATH, STDIN_PIPE,
183 &dumpout, &compout, &mesgf,
184 COMPRESS_PATH, compopt, NULL);
185 dbprintf(("%s: pid %ld: %s",
186 debug_prefix_time("-dump"), (long)comppid, COMPRESS_PATH));
187 if(compopt != skip_argument) {
188 dbprintf((" %s", compopt));
191 } else if (options->compress == COMPR_CUST) {
192 compopt = skip_argument;
193 comppid = pipespawn(options->clntcompprog, STDIN_PIPE,
194 &dumpout, &compout, &mesgf,
195 options->clntcompprog, compopt, NULL);
196 dbprintf(("%s: pid %ld: %s",
197 debug_prefix_time("-gnutar-cust"), (long)comppid, options->clntcompprog));
198 if(compopt != skip_argument) {
199 dbprintf((" %s", compopt));
208 device = amname_to_devname(amdevice);
209 fstype = amname_to_fstype(amdevice);
211 dbprintf(("%s: dumping device '%s' with '%s'\n",
212 debug_prefix_time(NULL), device, fstype));
214 #if defined(USE_RUNDUMP) || !defined(DUMP)
215 cmd = vstralloc(libexecdir, "/", "rundump", versionsuffix(), NULL);
216 if (g_options->config)
217 config = g_options->config;
221 cmd = stralloc(DUMP);
222 config = skip_argument;
225 #ifndef AIX_BACKUP /* { */
227 #ifdef XFSDUMP /* { */
229 if (strcmp(amname_to_fstype(amdevice), "xfs") == 0)
234 char *progname = cmd = newvstralloc(cmd, libexecdir, "/", "rundump",
235 versionsuffix(), NULL);
236 if (g_options->config)
237 config = g_options->config;
241 program->backup_name = XFSDUMP;
242 program->restore_name = XFSRESTORE;
244 indexcmd = vstralloc(XFSRESTORE,
250 " -e", " \'s/^/\\//\'",
254 start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
256 dumpkeys = stralloc(level_str);
257 dumppid = pipespawn(progname, STDIN_PIPE,
258 &dumpin, &dumpout, &mesgf,
261 options->no_record ? "-J" : skip_argument,
270 #ifdef VXDUMP /* { */
272 if (strcmp(amname_to_fstype(amdevice), "vxfs") == 0)
278 char *progname = cmd = newvstralloc(cmd, libexecdir, "/", "rundump",
279 versionsuffix(), NULL);
280 if (g_options->config)
281 config = g_options->config;
285 char *progname = cmd = newvstralloc(cmd, VXDUMP, NULL);
286 config = skip_argument;
288 program->backup_name = VXDUMP;
289 program->restore_name = VXRESTORE;
291 dumpkeys = vstralloc(level_str,
292 options->no_record ? "" : "u",
297 indexcmd = vstralloc(VXRESTORE,
305 start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
307 dumppid = pipespawn(progname, STDIN_PIPE,
308 &dumpin, &dumpout, &mesgf,
309 progname, config, /* JLM */
322 if (strcmp(amname_to_fstype(amdevice), "advfs") == 0)
327 char *progname = cmd = newvstralloc(cmd, libexecdir, "/", "rundump",
328 versionsuffix(), NULL);
329 if (g_options->config)
330 config = g_options->config;
333 device = newstralloc(device, amname_to_dirname(amdevice));
334 program->backup_name = VDUMP;
335 program->restore_name = VRESTORE;
337 dumpkeys = vstralloc(level_str,
338 options->no_record ? "" : "u",
343 indexcmd = vstralloc(VRESTORE,
347 "sed -e \'\n/^\\./ {\ns/^\\.//\ns/, [0-9]*$//\ns/^\\.//\ns/ @-> .*$//\nt\n}\nd\n\'",
351 start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
353 dumppid = pipespawn(cmd, STDIN_PIPE,
354 &dumpin, &dumpout, &mesgf,
368 #define RESTORE "restore"
371 dumpkeys = vstralloc(level_str,
372 options->no_record ? "" : "u",
374 #ifdef HAVE_HONOR_NODUMP
380 indexcmd = vstralloc(RESTORE,
383 /* not to /dev/null because of DU's dump */
389 start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
391 dumppid = pipespawn(cmd, STDIN_PIPE,
392 &dumpin, &dumpout, &mesgf,
397 #ifdef HAVE_HONOR_NODUMP
405 /* AIX backup program */
406 dumpkeys = vstralloc("-",
408 options->no_record ? "" : "u",
412 indexcmd = vstralloc(RESTORE,
421 start_index(options->createindex, dumpout, mesgf, indexf, indexcmd);
423 dumppid = pipespawn(cmd, STDIN_PIPE,
424 &dumpin, &dumpout, &mesgf,
439 /* close the write ends of the pipes */
446 if (options->createindex)
454 (void)status; /* Quiet unused parameter warning */
456 /* don't need to do anything for dump */
459 backup_program_t dump_program = {
469 re_table, start_backup, end_backup