Emmanuel Dreyfus <m...@netbsd.org> wrote: > Here is the -U flag patch augmented with a -H hash_pattern option, > which lets you partitionize given files-to-dump.
Erratum Index: dump.8 =================================================================== RCS file: /cvsroot/src/sbin/dump/dump.8,v retrieving revision 1.69 diff -U 4 -r1.69 dump.8 --- dump.8 15 Jul 2018 06:14:13 -0000 1.69 +++ dump.8 22 Mar 2019 02:27:16 -0000 @@ -43,15 +43,17 @@ .Op Fl B Ar records .Op Fl b Ar blocksize .Op Fl d Ar density .Op Fl f Ar file +.Op Fl H Ar hash_pattern .Op Fl h Ar level .Op Fl k Ar read-blocksize .Op Fl L Ar label .Op Fl l Ar timeout .Op Fl r Ar cachesize .Op Fl s Ar feet .Op Fl T Ar date +.Op Fl U Ar dumpdev .Op Fl x Ar snap-backup .Ar files-to-dump .Nm .Op Fl W Li \&| Fl w @@ -187,8 +189,19 @@ .Ev RCMD_CMD . See .Xr rcmd 3 for more details. +.It Fl H Ar hash_pattern +Within the list of given +.Ar files-to-dump +only dump the one whose name's SHA1 match +.Ar hash_pattern +pattern. This is usefull to perform partial dumps. Here is an example +to dump one quarter of paths matching +.Pa /home/* +.Bd -literal -offset indent +/sbin/dump -0f /dev/nrst1 -H '[0123]*' /home/* +.Ed .It Fl h Ar level Honor the user .Qq nodump flag @@ -298,12 +311,24 @@ 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 +If the +.Fl T +option is used or if a list of files or subdirectories is being dumped (as opposed to an entire file system), then .Fl u is ignored. +.It Fl U Ar dumpdev +Same as +.Fl u +but specifies the device in +.Pa /etc/dumpdates +as +.Ar dumpdev . +This option can be used with subdir dumps and with the +.Fl T +option. .It Fl W .Nm tells the operator what file systems need to be dumped. This information is gleaned from the files Index: dump.h =================================================================== RCS file: /cvsroot/src/sbin/dump/dump.h,v retrieving revision 1.56 diff -U 4 -r1.56 dump.h --- dump.h 1 Mar 2019 16:42:11 -0000 1.56 +++ dump.h 22 Mar 2019 02:27:16 -0000 @@ -114,8 +114,9 @@ const char *temp; /* name of the file for doing rewrite of dumpdates */ char lastlevel; /* dump level of previous dump */ char level; /* dump level of this dump */ int uflag; /* update flag */ +const char *dumpdev; /* device name in dumpdates */ int eflag; /* eject flag */ int lflag; /* autoload flag */ int diskfd; /* disk file descriptor */ int tapefd; /* tape file descriptor */ Index: itime.c =================================================================== RCS file: /cvsroot/src/sbin/dump/itime.c,v retrieving revision 1.21 diff -U 4 -r1.21 itime.c --- itime.c 1 Mar 2019 16:42:11 -0000 1.21 +++ itime.c 22 Mar 2019 02:27:16 -0000 @@ -128,11 +128,11 @@ getdumptime(void) { struct dumpdates *ddp; int i; - char *fname; + const char *fname; - fname = disk; + fname = dumpdev ? dumpdev : disk; #ifdef FDEBUG msg("Looking for name %s in dumpdates = %s for level = %c\n", fname, dumpdates, level); #endif @@ -169,17 +169,17 @@ FILE *df; struct dumpdates *dtwalk, *dtfound; int i; int fd; - char *fname; + const char *fname; - if(uflag == 0) + if(uflag == 0 && dumpdev == NULL) return; if ((df = fopen(dumpdates, "r+")) == NULL) quite(errno, "cannot rewrite %s", dumpdates); fd = fileno(df); (void) flock(fd, LOCK_EX); - fname = disk; + fname = dumpdev ? dumpdev : disk; free((char *)ddatev); ddatev = 0; nddates = 0; readdumptimes(df); Index: main.c =================================================================== RCS file: /cvsroot/src/sbin/dump/main.c,v retrieving revision 1.74 diff -U 4 -r1.74 main.c --- main.c 1 Mar 2019 16:42:11 -0000 1.74 +++ main.c 22 Mar 2019 02:27:17 -0000 @@ -55,9 +55,11 @@ #include <ctype.h> #include <err.h> #include <errno.h> #include <fcntl.h> +#include <fnmatch.h> #include <fstab.h> +#include <sha1.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -102,8 +104,9 @@ int snap_internal = 0; ino_t maxino; time_t tnow, date; int dirc; + char *hash_pattern = NULL; char *mountpoint; int just_estimate = 0; char labelstr[LBLSIZE]; char buf[MAXPATHLEN], rbuf[MAXPATHLEN]; @@ -132,9 +135,9 @@ usage(); obsolete(&argc, &argv); while ((ch = getopt(argc, argv, - "0123456789aB:b:cd:eFf:h:ik:l:L:nr:s:StT:uWwx:X")) != -1) + "0123456789aB:b:cd:eFf:H:h:ik:l:L:nr:s:StT:uU:Wwx:X")) != -1) switch (ch) { /* dump level */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -175,8 +178,11 @@ case 'f': /* output file */ tape = optarg; break; + case 'H': /* file to dump hash pattern */ + hash_pattern = optarg; + break; case 'h': honorlevel = numarg("honor level", 0L, 10L); break; @@ -244,8 +250,12 @@ case 'u': /* update /etc/dumpdates */ uflag = 1; break; + case 'U': /* dump device in /etc/dumpdates */ + dumpdev = optarg; + break; + case 'W': /* what to do */ case 'w': lastdump(ch); exit(X_FINOK); /* do nothing else */ @@ -319,11 +329,35 @@ } else { if (strcmp(mountpoint, fsbuf.f_mntonname) != 0) quit("%s is not on %s", argv[i], mountpoint); } + + if (hash_pattern) { + char hash[SHA1_DIGEST_STRING_LENGTH]; + uint8_t *arg = (uint8_t *)argv[i]; + int j; + + (void)SHA1Data(arg, strlen(argv[i]), hash); + + if (fnmatch(hash_pattern, hash, 0) != 0) { + for (j = i; j < argc - 1; j++) { + argv[j] = argv[j + 1]; + } + argc--; + i--; + continue; + } + } + msg("Dumping file/directory %s\n", argv[i]); dirc++; } + + if (hash_pattern && dirc == 0) { + msg("-H option mached no provided files-to-dump, exitting\n"); + exit(X_FINOK); + } + if (mountpoint) free(mountpoint); if (dirc == 0) { @@ -671,11 +705,11 @@ const char *prog = getprogname(); (void)fprintf(stderr, "usage: %s [-0123456789aceFinStuX] [-B records] [-b blocksize]\n" -" [-d density] [-f file] [-h level] [-k read-blocksize]\n" -" [-L label] [-l timeout] [-r cachesize] [-s feet]\n" -" [-T date] [-x snap-backup] files-to-dump\n" +" [-d density] [-f file] [-h level] [-H hash_pattern]\n" +" [-k read-blocksize] [-L label] [-l timeout] [-r cachesize]\n" +" [-s feet] [-T date] [-U dumpdev] [-x snap-backup] files-to-dump\n" " %s [-W | -w]\n", prog, prog); exit(X_STARTUP); } -- Emmanuel Dreyfus http://hcpnet.free.fr/pubz m...@netbsd.org