2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
4 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of U.M. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. U.M. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Authors: the Amanda Development Team. Its members are listed in a
25 * file named AUTHORS, in the root directory of this distribution.
28 * $Id: sendbackup-dump.c,v 1.90 2006/07/25 18:10:07 martinea Exp $
30 * send backup data using BSD dump
34 #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, 1),
45 AM_SIZE_RE("dump: Actual: [0-9][0-9]* tape blocks", 1024, 1),
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 \\([0-9][0-9]*KB\\)",
58 AM_SIZE_RE("DUMP: [0-9][0-9]* blocks \\([0-9][0-9]*\\.[0-9][0-9]*MB\\)",
60 AM_SIZE_RE("DUMP: [0-9][0-9]* blocks", 512, 1),
61 AM_SIZE_RE("DUMP: [0-9][0-9]* bytes were dumped", 1, 1),
63 AM_SIZE_RE("vdump: Dumped [0-9][0-9]* of [0-9][0-9]* bytes", 1, 1),
65 AM_SIZE_RE("dump: Actual: [0-9][0-9]* blocks output to pipe", 1024, 1),
67 AM_SIZE_RE("dump: Dumped [0-9][0-9]* of [0-9][0-9]* bytes", 1, 1),
69 AM_SIZE_RE("DUMP: [0-9][0-9]* KB actual output", 1024, 1),
70 /* HPUX 10.20 and above vxdump */
71 AM_SIZE_RE("vxdump: [0-9][0-9]* tape blocks", 1024, 1),
73 AM_SIZE_RE("vxdump: [0-9][0-9]* blocks", 1024, 1),
75 AM_SIZE_RE(" VXDUMP: [0-9][0-9]* blocks", 512, 1),
77 AM_SIZE_RE(" UFSDUMP: [0-9][0-9]* blocks", 512, 1),
78 /* Irix 6.2 xfs dump */
79 AM_SIZE_RE("xfsdump: media file size [0-9][0-9]* bytes", 1, 1),
81 AM_SIZE_RE("DUMP: [0-9][0-9]* KB", 1024, 1),
83 /* strange dump lines */
84 AM_STRANGE_RE("should not happen"),
85 AM_STRANGE_RE("Cannot open"),
86 AM_STRANGE_RE("[Ee]rror"),
87 AM_STRANGE_RE("[Ff]ail"),
88 /* XXX add more ERROR entries here by scanning dump sources? */
90 /* any blank or non-strange DUMP: lines are marked as normal */
91 AM_NORMAL_RE("^ *DUMP:"),
92 AM_NORMAL_RE("^dump:"), /* OSF/1 */
93 AM_NORMAL_RE("^vdump:"), /* OSF/1 */
94 AM_NORMAL_RE("^ *vxdump:"), /* HPUX10 */
95 AM_NORMAL_RE("^ *vxfs *vxdump:"), /* Solaris */
96 AM_NORMAL_RE("^Dumping .* to stdout"), /* Sol vxdump */
97 AM_NORMAL_RE("^xfsdump:"), /* IRIX xfs */
98 AM_NORMAL_RE("^ *VXDUMP:"), /* Sinix */
99 AM_NORMAL_RE("^ *UFSDUMP:"), /* Sinix */
101 #ifdef VDUMP /* this is for OSF/1 3.2's vdump for advfs */
102 AM_NORMAL_RE("^The -s option is ignored"), /* OSF/1 */
103 AM_NORMAL_RE("^path"), /* OSF/1 */
104 AM_NORMAL_RE("^dev/fset"), /* OSF/1 */
105 AM_NORMAL_RE("^type"), /* OSF/1 */
106 AM_NORMAL_RE("^advfs id"), /* OSF/1 */
107 AM_NORMAL_RE("^[A-Z][a-z][a-z] [A-Z][a-z][a-z] .[0-9] [0-9]"), /* OSF/1 */
110 AM_NORMAL_RE("^backup:"), /* AIX */
111 AM_NORMAL_RE("^ Use the umount command to unmount the filesystem"),
113 AM_NORMAL_RE("^[ \t]*$"),
115 /* catch-all; DMP_STRANGE is returned for all other lines */
119 static void start_backup(dle_t *dle, char *host,
120 int dataf, int mesgf, int indexf);
121 static void end_backup(dle_t *dle, int status);
124 * doing similar to $ dump | compression | encryption
135 int dumpin, dumpout, compout;
136 char *dumpkeys = NULL;
141 char *indexcmd = NULL;
142 char level_str[NUM_STR_SIZE];
143 char *compopt = NULL;
144 char *encryptopt = skip_argument;
147 am_level_t *alevel = (am_level_t *)dle->levellist->data;
148 int level = alevel->level;
150 g_snprintf(level_str, SIZEOF(level_str), "%d", level);
152 qdisk = quote_string(dle->disk);
153 dbprintf(_("start: %s:%s lev %d\n"), host, qdisk, level);
155 g_fprintf(stderr, _("%s: start [%s:%s level %d]\n"),
156 get_pname(), host, qdisk, level);
159 /* apply client-side encryption here */
160 if (dle->encrypt == ENCRYPT_CUST ) {
161 encpid = pipespawn(dle->clnt_encrypt, STDIN_PIPE, 0,
162 &compout, &dataf, &mesgf,
163 dle->clnt_encrypt, encryptopt, NULL);
164 dbprintf(_("gnutar: pid %ld: %s\n"), (long)encpid, dle->clnt_encrypt);
169 /* now do the client-side compression */
172 if(dle->compress == COMP_FAST || dle->compress == COMP_BEST) {
173 compopt = skip_argument;
175 #if defined(COMPRESS_BEST_OPT) && defined(COMPRESS_FAST_OPT)
176 if(dle->compress == COMP_BEST) {
177 compopt = COMPRESS_BEST_OPT;
179 compopt = COMPRESS_FAST_OPT;
182 comppid = pipespawn(COMPRESS_PATH, STDIN_PIPE, 0,
183 &dumpout, &compout, &mesgf,
184 COMPRESS_PATH, compopt, NULL);
185 dbprintf(_("dump: pid %ld: %s"), (long)comppid, COMPRESS_PATH);
186 if(compopt != skip_argument) {
187 dbprintf(" %s", compopt);
190 } else if (dle->compress == COMP_CUST) {
191 compopt = skip_argument;
192 comppid = pipespawn(dle->compprog, STDIN_PIPE, 0,
193 &dumpout, &compout, &mesgf,
194 dle->compprog, compopt, NULL);
195 dbprintf(_("gnutar-cust: pid %ld: %s"),
196 (long)comppid, dle->compprog);
197 if(compopt != skip_argument) {
198 dbprintf(" %s", compopt);
207 device = amname_to_devname(dle->device);
208 fstype = amname_to_fstype(dle->device);
210 dbprintf(_("dumping device '%s' with '%s'\n"), device, fstype);
212 #if defined(USE_RUNDUMP) || !defined(DUMP)
213 cmd = vstralloc(amlibexecdir, "/", "rundump", NULL);
215 if (g_options->config)
216 config = g_options->config;
220 cmd = stralloc(DUMP);
221 cmdX = skip_argument;
222 config = skip_argument;
225 #ifndef AIX_BACKUP /* { */
227 #ifdef XFSDUMP /* { */
229 if (strcmp(amname_to_fstype(dle->device), "xfs") == 0)
234 char *progname = cmd = newvstralloc(cmd, amlibexecdir, "/", "rundump",
237 if (g_options->config)
238 config = g_options->config;
242 program->backup_name = XFSDUMP;
243 program->restore_name = XFSRESTORE;
245 indexcmd = vstralloc(XFSRESTORE,
251 " -e", " \'s/^/\\//\'",
253 info_tapeheader(dle);
255 start_index(dle->create_index, dumpout, mesgf, indexf, indexcmd);
257 dumpkeys = stralloc(level_str);
258 dumppid = pipespawn(progname, STDIN_PIPE, 0,
259 &dumpin, &dumpout, &mesgf,
262 !dle->record ? "-J" : skip_argument,
271 #ifdef VXDUMP /* { */
273 if (strcmp(amname_to_fstype(dle->device), "vxfs") == 0)
279 char *progname = cmd = newvstralloc(cmd, amlibexecdir, "/", "rundump",
282 if (g_options->config)
283 config = g_options->config;
287 char *progname = cmd = newvstralloc(cmd, VXDUMP, NULL);
288 cmdX = skip_argument;
289 config = skip_argument;
291 program->backup_name = VXDUMP;
292 program->restore_name = VXRESTORE;
294 dumpkeys = vstralloc(level_str,
295 !dle->record ? "" : "u",
300 indexcmd = vstralloc(VXRESTORE,
306 info_tapeheader(dle);
308 start_index(dle->create_index, dumpout, mesgf, indexf, indexcmd);
310 dumppid = pipespawn(progname, STDIN_PIPE, 0,
311 &dumpin, &dumpout, &mesgf,
325 if (strcmp(amname_to_fstype(dle->device), "advfs") == 0)
330 cmd = newvstralloc(cmd, amlibexecdir, "/", "rundump", NULL);
332 if (g_options->config)
333 config = g_options->config;
336 device = newstralloc(device, amname_to_dirname(dle->device));
337 program->backup_name = VDUMP;
338 program->restore_name = VRESTORE;
340 dumpkeys = vstralloc(level_str,
341 !dle->record ? "" : "u",
346 indexcmd = vstralloc(VRESTORE,
350 "sed -e \'\n/^\\./ {\ns/^\\.//\ns/, [0-9]*$//\ns/^\\.//\ns/ @-> .*$//\nt\n}\nd\n\'",
352 info_tapeheader(dle);
354 start_index(dle->create_index, dumpout, mesgf, indexf, indexcmd);
356 dumppid = pipespawn(cmd, STDIN_PIPE, 0,
357 &dumpin, &dumpout, &mesgf,
371 #define RESTORE "restore"
374 #ifdef HAVE_HONOR_NODUMP
375 # define PARAM_HONOR_NODUMP "h"
377 # define PARAM_HONOR_NODUMP ""
381 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 500043)
382 # define FREEBSD_EXTRA_KEYS "bL"
384 # define FREEBSD_EXTRA_KEYS "b"
387 # define FREEBSD_EXTRA_KEYS ""
390 dumpkeys = vstralloc(level_str,
391 !dle->record ? "" : "u",
398 indexcmd = vstralloc(RESTORE,
401 /* not to /dev/null because of DU's dump */
405 info_tapeheader(dle);
407 start_index(dle->create_index, dumpout, mesgf, indexf, indexcmd);
409 dumppid = pipespawn(cmd, STDIN_PIPE, 0,
410 &dumpin, &dumpout, &mesgf,
418 #ifdef HAVE_HONOR_NODUMP
426 /* AIX backup program */
427 dumpkeys = vstralloc("-",
429 !dle->record ? "" : "u",
433 indexcmd = vstralloc(RESTORE,
440 info_tapeheader(dle);
442 start_index(dle->create_index, dumpout, mesgf, indexf, indexcmd);
444 dumppid = pipespawn(cmd, STDIN_PIPE, 0,
445 &dumpin, &dumpout, &mesgf,
460 /* close the write ends of the pipes */
467 if (dle->create_index)
477 (void)status; /* Quiet unused parameter warning */
479 /* don't need to do anything for dump */
482 backup_program_t dump_program = {
492 re_table, start_backup, end_backup