diff --git a/sbin/dump/dump.8 b/sbin/dump/dump.8 index 39e01e455b6d..25775e56bde6 100644 --- a/sbin/dump/dump.8 +++ b/sbin/dump/dump.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: dump.8,v 1.15 1997/04/15 07:00:45 lukem Exp $ +.\" $NetBSD: dump.8,v 1.16 1997/06/05 11:13:18 lukem Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" Regents of the University of California. @@ -34,14 +34,14 @@ .\" .\" @(#)dump.8 8.1 (Berkeley) 6/16/93 .\" -.Dd June 16, 1993 +.Dd June 4, 1997 .Dt DUMP 8 .Os BSD 4 .Sh NAME .Nm dump .Nd filesystem backup .Sh SYNOPSIS -.Nm dump +.Nm .Op Fl 0123456789cnu .Op Fl B Ar records .Op Fl b Ar blocksize @@ -50,7 +50,7 @@ .Op Fl h Ar level .Op Fl s Ar feet .Op Fl T Ar date -.Ar filesystem +.Ar files-to-dump .Nm dump .Op Fl W Li \&| Fl w .Pp @@ -60,7 +60,7 @@ option syntax is implemented for backward compatibility, but is not documented here.) .Sh DESCRIPTION -.Nm Dump +.Nm examines files on a filesystem and determines which files @@ -81,6 +81,18 @@ block count options below. By default, the same output file name is used for each volume after prompting the operator to change media. .Pp +.Ar files-to-dump +is either a mountpoint of a filesystem, +or a list of files and directories on a single filesystem to be backed +up as a subset of the filesystem. +In the former case, either the path to a mounted filesystem, +or the device of an unmounted filesystem can be used. +In the latter case, certain restrictions are placed on the backup: +.Fl u +is ignored, the only dump level that is supported is +.Fl 0 , +and all of the files must reside on the same filesystem. +.Pp The following options are supported by .Nm dump : .Bl -tag -width Ds @@ -134,7 +146,7 @@ If the name of the file is of the form .Dq host:file , or .Dq user@host:file , -.Nm dump +.Nm writes to the named file on the remote host using .Xr rmt 8 . .It Fl h Ar level @@ -149,7 +161,7 @@ so that incremental backups omit such files but full backups retain them. .It Fl n Whenever -.Nm dump +.Nm requires operator attention, notify all operators in the group .Dq operator @@ -159,7 +171,7 @@ by means similar to a Attempt to calculate the amount of tape needed at a particular density. If this amount is exceeded, -.Nm dump +.Nm prompts for a new tape. It is recommended to be a bit conservative on this option. The default tape length is 2300 feet. @@ -194,8 +206,12 @@ The file .Pa /etc/dumpdates may be edited to change any of the fields, if necessary. +If a list of files or subdirectories is being dumped +(as opposed to and entire filesystem), then +.Fl u +is ignored. .It Fl W -.Nm Dump +.Nm tells the operator what file systems need to be dumped. This information is gleaned from the files .Pa /etc/dumpdates @@ -204,7 +220,7 @@ and The .Fl W flag causes -.Nm dump +.Nm to print out, for each file system in .Pa /etc/dumpdates the most recent dump date and level, @@ -212,13 +228,13 @@ and highlights those file systems that should be dumped. If the .Fl W flag is set, all other options are ignored, and -.Nm dump +.Nm exits immediately. .It Fl w Is like W, but prints only those filesystems which need to be dumped. .El .Pp -.Nm Dump +.Nm requires operator intervention on these conditions: end of tape, end of dump, @@ -228,15 +244,15 @@ disk read error (if there are more than a threshold of 32). In addition to alerting all operators implied by the .Fl n flag, -.Nm dump +.Nm interacts with the operator on .Nm dump Ns 's control terminal at times when -.Nm dump +.Nm can no longer proceed, or if something is grossly wrong. All questions -.Nm dump +.Nm poses .Em must be answered by typing @@ -246,17 +262,17 @@ or appropriately. .Pp Since making a dump involves a lot of time and effort for full dumps, -.Nm dump +.Nm checkpoints itself at the start of each tape volume. If writing that volume fails for some reason, -.Nm dump +.Nm will, with operator permission, restart itself from the checkpoint after the old tape has been rewound and removed, and a new tape has been mounted. .Pp -.Nm Dump +.Nm tells the operator what is going on at periodic intervals, including usually low estimates of the number of blocks to write, the number of tapes it will take, the time to completion, and @@ -264,7 +280,7 @@ the time to the tape change. The output is verbose, so that others know that the terminal controlling -.Nm dump +.Nm is busy, and will be for some time. .Pp @@ -301,6 +317,19 @@ used, also on a cyclical basis. .Pp After several months or so, the daily and weekly tapes should get rotated out of the dump cycle and fresh tapes brought in. +.Pp +If +.Nm +receives a +.Dv SIGINFO +signal +(see the +.Dq status +argument of +.Xr stty 1 ) +whilst a backup is in progress, statistics on the amount completed, +current transfer rate, and estimated finished time, will be written +to the standard error output. .Sh FILES .Bl -tag -width /etc/dumpdates -compact .It Pa /dev/rst0 @@ -316,14 +345,16 @@ to find group .Em operator .El .Sh SEE ALSO +.Xr dump 5 , +.Xr fstab 5 , .Xr restore 8 , .Xr rmt 8 , -.Xr dump 5 , -.Xr fstab 5 +.Xr stty 1 .Sh DIAGNOSTICS Many, and verbose. .Pp -Dump exits with zero status on success. +.Nm +exits with zero status on success. Startup errors are indicated with an exit code of 1; abnormal termination is indicated with an exit code of 3. .Sh BUGS @@ -333,7 +364,7 @@ Each reel requires a new process, so parent processes for reels already written just hang around until the entire tape is written. .Pp -.Nm Dump +.Nm with the .Fl W or @@ -344,8 +375,13 @@ in even if listed in .Pa /etc/fstab . .Pp +When dumping a list of files or subdirectories, access privileges are +required to scan the directory (as this is done via the +.Xr fts 3 +routines rather than directly accessing the filesystem). +.Pp It would be nice if -.Nm dump +.Nm knew about the dump sequence, kept track of the tapes scribbled on, told the operator which tape to mount when, @@ -354,5 +390,5 @@ for the operator running .Xr restore . .Sh HISTORY A -.Nm dump +.Nm command appeared in Version 6 AT&T UNIX. diff --git a/sbin/dump/dump.h b/sbin/dump/dump.h index 64f4ca90ebe9..f2ca638e9818 100644 --- a/sbin/dump/dump.h +++ b/sbin/dump/dump.h @@ -1,4 +1,4 @@ -/* $NetBSD: dump.h,v 1.10 1997/04/10 05:36:23 lukem Exp $ */ +/* $NetBSD: dump.h,v 1.11 1997/06/05 11:13:20 lukem Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -101,13 +101,16 @@ int query __P((char *question)); void quit __P((const char *fmt, ...)); void set_operators __P((void)); time_t do_stats __P((void)); +void statussig __P((int)); void timeest __P((void)); time_t unctime __P((char *str)); /* mapping routines */ struct dinode; long blockest __P((struct dinode *dp)); -int mapfiles __P((ino_t maxino, long *tapesize)); +void mapfileino __P((ino_t, long *, int *)); +int mapfiles __P((ino_t maxino, long *tapesize, char *disk, + char * const *dirv)); int mapdirs __P((ino_t maxino, long *tapesize)); /* file dumping routines */ diff --git a/sbin/dump/dumprmt.c b/sbin/dump/dumprmt.c index c3ef93fee039..bfdc79f2e7cc 100644 --- a/sbin/dump/dumprmt.c +++ b/sbin/dump/dumprmt.c @@ -1,4 +1,4 @@ -/* $NetBSD: dumprmt.c,v 1.15 1997/05/27 08:35:27 mrg Exp $ */ +/* $NetBSD: dumprmt.c,v 1.16 1997/06/05 11:13:23 lukem Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)dumprmt.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$NetBSD: dumprmt.c,v 1.15 1997/05/27 08:35:27 mrg Exp $"; +static char rcsid[] = "$NetBSD: dumprmt.c,v 1.16 1997/06/05 11:13:23 lukem Exp $"; #endif #endif /* not lint */ @@ -91,8 +91,6 @@ static void rmtgets __P((char *, int)); static int rmtreply __P((char *)); extern int ntrec; /* blocking factor on tape */ -extern uid_t uid; /* real uid */ -extern uid_t euid; /* effective uid */ int rmthost(host) diff --git a/sbin/dump/main.c b/sbin/dump/main.c index 903456c15e50..9eed8ad6b92b 100644 --- a/sbin/dump/main.c +++ b/sbin/dump/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.13 1997/05/27 08:35:28 mrg Exp $ */ +/* $NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $ */ /*- * Copyright (c) 1980, 1991, 1993, 1994 @@ -43,12 +43,15 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 4/15/94"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.13 1997/05/27 08:35:28 mrg Exp $"; +static char rcsid[] = "$NetBSD: main.c,v 1.14 1997/06/05 11:13:24 lukem Exp $"; #endif #endif /* not lint */ #include #include +#include +#include + #ifdef sunos #include @@ -108,6 +111,8 @@ main(argc, argv) int i, anydirskipped, bflag = 0, Tflag = 0, honorlevel = 1; ino_t maxino; time_t tnow; + int dirlist; + char *toplevel; spcl.c_date = 0; (void)time((time_t *)&spcl.c_date); @@ -198,14 +203,66 @@ main(argc, argv) (void)fprintf(stderr, "Must specify disk or filesystem\n"); exit(X_ABORT); } - disk = *argv++; - argc--; - if (argc >= 1) { - (void)fprintf(stderr, "Unknown arguments to dump:"); - while (argc--) - (void)fprintf(stderr, " %s", *argv++); - (void)fprintf(stderr, "\n"); - exit(X_ABORT); + + /* + * determine if disk is a subdirectory, and setup appropriately + */ + dirlist = 0; + toplevel = NULL; + for (i = 0; i < argc; i++) { + struct stat sb; + struct statfs fsbuf; + + if (lstat(argv[i], &sb) == -1) { + msg("Cannot lstat %s: %s\n", argv[i], strerror(errno)); + exit(X_ABORT); + } + if (!S_ISDIR(sb.st_mode) && !S_ISREG(sb.st_mode)) + break; + if (statfs(argv[i], &fsbuf) == -1) { + msg("Cannot statfs %s: %s\n", argv[i], strerror(errno)); + exit(X_ABORT); + } + if (strcmp(argv[i], fsbuf.f_mntonname) == 0) { + if (dirlist != 0) { + msg("Can't dump a mountpoint and a filelist\n"); + exit(X_ABORT); + } + break; /* exit if sole mountpoint */ + } + if (!disk) { + if ((toplevel = strdup(fsbuf.f_mntonname)) == NULL) { + msg("Cannot malloc diskname\n"); + exit(X_ABORT); + } + disk = toplevel; + if (uflag) { + msg("Ignoring u flag for subdir dump\n"); + uflag = 0; + } + if (level > '0') { + msg("Subdir dump is done at level 0\n"); + level = '0'; + } + msg("Dumping sub files/directories from %s\n", disk); + } else { + if (strcmp(disk, fsbuf.f_mntonname) != 0) { + msg("%s is not on %s\n", argv[i], disk); + exit(X_ABORT); + } + } + msg("Dumping file/directory %s\n", argv[i]); + dirlist++; + } + if (dirlist == 0) { + disk = *argv++; + if (argc != 1) { + (void)fprintf(stderr, "Excess arguments to dump:"); + while (--argc) + (void)fprintf(stderr, " %s", *argv++); + (void)fprintf(stderr, "\n"); + exit(X_ABORT); + } } if (Tflag && uflag) { (void)fprintf(stderr, @@ -265,6 +322,7 @@ main(argc, argv) set_operators(); /* /etc/group snarfed */ getfstab(); /* /etc/fstab snarfed */ + /* * disk can be either the full special file name, * the suffix of the special file name, @@ -275,7 +333,11 @@ main(argc, argv) if (dt != NULL) { disk = rawname(dt->fs_spec); (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); - (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); + if (dirlist != 0) + (void)snprintf(spcl.c_filesys, NAMELEN, + "a subset of %s", dt->fs_file); + else + (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); } else { (void)strncpy(spcl.c_dev, disk, NAMELEN); (void)strncpy(spcl.c_filesys, "an unlisted file system", @@ -329,8 +391,11 @@ main(argc, argv) nonodump = spcl.c_level < honorlevel; + (void)signal(SIGINFO, statussig); + msg("mapping (Pass I) [regular files]\n"); - anydirskipped = mapfiles(maxino, &tapesize); + anydirskipped = mapfiles(maxino, &tapesize, toplevel, + (dirlist ? argv : NULL)); msg("mapping (Pass II) [directories]\n"); while (anydirskipped) { @@ -445,7 +510,7 @@ main(argc, argv) msg("Date of this level %c dump: %s", level, spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date)); msg("Date this dump completed: %s", ctime(&tnow)); - msg("Average transfer rate: %ldK/s\n", xferrate / tapeno); + msg("Average transfer rate: %ld KB/s\n", xferrate / tapeno); putdumptime(); trewind(); broadcast("DUMP IS DONE!\7\7\n"); @@ -550,7 +615,7 @@ obsolete(argcp, argvp) /* Allocate space for new arguments. */ if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL || (p = flagsp = malloc(strlen(ap) + 2)) == NULL) - err(1, NULL); + err(1, "malloc"); *nargv++ = *argv; argv += 2; @@ -569,7 +634,7 @@ obsolete(argcp, argvp) usage(); } if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL) - err(1, NULL); + err(1, "malloc"); nargv[0][0] = '-'; nargv[0][1] = *ap; (void)strcpy(&nargv[0][2], *argv); /* XXX strcpy is safe */ @@ -593,7 +658,8 @@ obsolete(argcp, argvp) } /* Copy remaining arguments. */ - while (*nargv++ = *argv++); + while ((*nargv++ = *argv++) != NULL) + ; /* Update argument count. */ *argcp = nargv - *argvp - 1; diff --git a/sbin/dump/tape.c b/sbin/dump/tape.c index 5fbf05dbcd18..79384bbef926 100644 --- a/sbin/dump/tape.c +++ b/sbin/dump/tape.c @@ -1,4 +1,4 @@ -/* $NetBSD: tape.c,v 1.10 1997/04/15 07:00:49 lukem Exp $ */ +/* $NetBSD: tape.c,v 1.11 1997/06/05 11:13:26 lukem Exp $ */ /*- * Copyright (c) 1980, 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)tape.c 8.2 (Berkeley) 3/17/94"; #else -static char rcsid[] = "$NetBSD: tape.c,v 1.10 1997/04/15 07:00:49 lukem Exp $"; +static char rcsid[] = "$NetBSD: tape.c,v 1.11 1997/06/05 11:13:26 lukem Exp $"; #endif #endif /* not lint */ @@ -260,13 +260,38 @@ do_stats() if (ttaken > 0) { msg("Volume %d took %d:%02d:%02d\n", tapeno, ttaken / 3600, (ttaken % 3600) / 60, ttaken % 60); - msg("Volume %d transfer rate: %ldK/s\n", tapeno, + msg("Volume %d transfer rate: %ld KB/s\n", tapeno, blocks / ttaken); xferrate += blocks / ttaken; } return(tnow); } +/* + * statussig -- + * information message upon receipt of SIGINFO + * (derived from optr.c::timeest()) + */ +void +statussig(notused) + int notused; +{ + time_t tnow, deltat; + char msgbuf[128]; + + if (blockswritten < 500) + return; + (void) time((time_t *) &tnow); + deltat = tstart_writing - tnow + (1.0 * (tnow - tstart_writing)) + / blockswritten * tapesize; + (void)snprintf(msgbuf, sizeof(msgbuf), + "%3.2f%% done at %ld KB/s, finished in %d:%02d\n", + (blockswritten * 100.0) / tapesize, + (spcl.c_tapea - tapea_volume) / (tnow - tstart_volume), + (int)(deltat / 3600), (int)((deltat % 3600) / 60)); + write(STDERR_FILENO, msgbuf, strlen(msgbuf)); +} + static void flushtape() { @@ -741,6 +766,7 @@ enslave() for (j = 0; j <= i; j++) (void) close(slaves[j].fd); signal(SIGINT, SIG_IGN); /* Master handles this */ + signal(SIGINFO, SIG_IGN); doslave(cmd[0], i); Exit(X_FINOK); } diff --git a/sbin/dump/traverse.c b/sbin/dump/traverse.c index bfcde0e1204d..0ace0d3597ea 100644 --- a/sbin/dump/traverse.c +++ b/sbin/dump/traverse.c @@ -1,4 +1,4 @@ -/* $NetBSD: traverse.c,v 1.16 1997/04/15 01:09:54 lukem Exp $ */ +/* $NetBSD: traverse.c,v 1.17 1997/06/05 11:13:27 lukem Exp $ */ /*- * Copyright (c) 1980, 1988, 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)traverse.c 8.2 (Berkeley) 9/23/93"; #else -static char rcsid[] = "$NetBSD: traverse.c,v 1.16 1997/04/15 01:09:54 lukem Exp $"; +static char rcsid[] = "$NetBSD: traverse.c,v 1.17 1997/06/05 11:13:27 lukem Exp $"; #endif #endif /* not lint */ @@ -59,6 +59,8 @@ static char rcsid[] = "$NetBSD: traverse.c,v 1.16 1997/04/15 01:09:54 lukem Exp #include #include +#include +#include #include #ifdef __STDC__ #include @@ -133,6 +135,36 @@ blockest(dp) #define WANTTODUMP(dp) CHANGEDSINCE(dp, spcl.c_ddate) #endif +/* + * Determine if given inode should be dumped + */ +void +mapfileino(ino, tapesize, dirskipped) + ino_t ino; + long *tapesize; + int *dirskipped; +{ + int mode; + struct dinode *dp; + + dp = getino(ino); + if ((mode = (dp->di_mode & IFMT)) == 0) + return; + SETINO(ino, usedinomap); + if (mode == IFDIR) + SETINO(ino, dumpdirmap); + if (WANTTODUMP(dp)) { + SETINO(ino, dumpinomap); + if (mode != IFREG && mode != IFDIR && mode != IFLNK) + *tapesize += 1; + else + *tapesize += blockest(dp); + return; + } + if (mode == IFDIR) + *dirskipped = 1; +} + /* * Dump pass 1. * @@ -141,32 +173,87 @@ blockest(dp) * the directories in the filesystem. */ int -mapfiles(maxino, tapesize) +mapfiles(maxino, tapesize, disk, dirv) ino_t maxino; long *tapesize; + char *disk; + char * const *dirv; { - int mode; - ino_t ino; - struct dinode *dp; int anydirskipped = 0; - for (ino = ROOTINO; ino < maxino; ino++) { - dp = getino(ino); - if ((mode = (dp->di_mode & IFMT)) == 0) - continue; - SETINO(ino, usedinomap); - if (mode == IFDIR) - SETINO(ino, dumpdirmap); - if (WANTTODUMP(dp)) { - SETINO(ino, dumpinomap); - if (mode != IFREG && mode != IFDIR && mode != IFLNK) - *tapesize += 1; - else - *tapesize += blockest(dp); - continue; + if (dirv != NULL) { + char curdir[MAXPATHLEN]; + FTS *dirh; + FTSENT *entry; + int d; + + if (getcwd(curdir, sizeof(curdir)) == NULL) { + msg("Can't determine cwd: %s\n", strerror(errno)); + dumpabort(0); + } + if ((dirh = fts_open(dirv, FTS_PHYSICAL|FTS_SEEDOT|FTS_XDEV, + (int (*)())NULL)) == NULL) { + msg("fts_open failed: %s\n", strerror(errno)); + dumpabort(0); + } + while ((entry = fts_read(dirh)) != NULL) { + switch (entry->fts_info) { + case FTS_DNR: /* an error */ + case FTS_ERR: + case FTS_NS: + msg("Can't fts_read %s: %s\n", entry->fts_path, + strerror(errno)); + case FTS_DP: /* already seen dir */ + continue; + } + mapfileino(entry->fts_statp->st_ino, tapesize, + &anydirskipped); + } + (void)fts_close(dirh); + + /* + * Add any parent directories + */ + for (d = 0 ; dirv[d] != NULL ; d++) { + char path[MAXPATHLEN]; + + if (dirv[d][0] != '/') + (void)snprintf(path, sizeof(path), "%s/%s", + curdir, dirv[d]); + else + (void)snprintf(path, sizeof(path), "%s", + dirv[d]); + while (strcmp(path, disk) != 0) { + char *p; + struct stat sb; + + if (*path == '\0') + break; + if ((p = strrchr(path, '/')) == NULL) + break; + if (p == path) + break; + *p = '\0'; + if (stat(path, &sb) == -1) { + msg("Can't stat %s: %s\n", path, + strerror(errno)); + break; + } + mapfileino(sb.st_ino, tapesize, &anydirskipped); + } + } + + /* + * Ensure that the root inode actually appears in the + * file list for a subdir + */ + mapfileino(ROOTINO, tapesize, &anydirskipped); + } else { + ino_t ino; + + for (ino = ROOTINO; ino < maxino; ino++) { + mapfileino(ino, tapesize, &anydirskipped); } - if (mode == IFDIR) - anydirskipped = 1; } /* * Restore gets very upset if the root is not dumped,