Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Feb 2004 23:56:44 +0100
From:      Frode Nordahl <frode@nordahl.net>
To:        current@freebsd.org
Subject:   patch: teaching dump(8) to change tapes
Message-ID:  <3CAA4153-569C-11D8-8876-000A95A9A574@nordahl.net>

next in thread | raw e-mail | index | archive | help

--Apple-Mail-14-905039896
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Hello,

Wrote a small and simple patch to teach dump(8) to change tapes via a 
external script.

This sure helps me, not sure if it's ready for or even wanted for 
commit though :)

I think using a script for this is wise because there is a myriad of 
tape robot systems out there, pair that with a myriad of different 
sysadmins with a myriad different backup strategies, and you got a 
situation impossible to map in a generic program such as dump, let them 
sh or perl it themselves.

Any comments?

Adds "-F /some/where/script" as an option.

The script gets device name and current volume number passed on the 
command line.

Name of the option and arguments to the script are inspired by the GNU 
counterpart (as of the man page).  If we didn't think of it first, 
let's at least make it compatible :)

mvh,
Frode


--Apple-Mail-14-905039896
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="dump.patch"
Content-Disposition: attachment;
	filename=dump.patch

Only in dump: cache.o
Only in dump: dump
Only in dump: dump.8.gz
diff -ru /usr/src/sbin/dump/dump.h dump/dump.h
--- /usr/src/sbin/dump/dump.h	Tue Nov  4 13:27:18 2003
+++ dump/dump.h	Tue Feb  3 19:38:57 2004
@@ -62,6 +62,7 @@
 char	*tape;		/* name of the tape file */
 char	*dumpdates;	/* name of the file containing dump date information*/
 char	*temp;		/* name of the file for doing rewrite of dumpdates */
+char	*script;	/* name of the script for changing tapes */
 char	lastlevel;	/* dump level of previous dump */
 char	level;		/* dump level of this dump */
 int	uflag;		/* update flag */
Only in dump: dumprmt.o
Only in dump: itime.o
diff -ru /usr/src/sbin/dump/main.c dump/main.c
--- /usr/src/sbin/dump/main.c	Sun Nov 16 09:01:58 2003
+++ dump/main.c	Tue Feb  3 21:31:35 2004
@@ -127,7 +127,7 @@
 
 	obsolete(&argc, &argv);
 	while ((ch = getopt(argc, argv,
-	    "0123456789aB:b:C:cD:d:f:h:LnSs:T:uWw")) != -1)
+	    "0123456789aB:b:C:cD:d:f:F:h:LnSs:T:uWw")) != -1)
 		switch (ch) {
 		/* dump level */
 		case '0': case '1': case '2': case '3': case '4':
@@ -171,6 +171,10 @@
 			tape = optarg;
 			break;
 
+		case 'F':		/* changer script */
+			script = optarg;
+			break;
+
 		case 'h':
 			honorlevel = numarg("honor level", 0L, 10L);
 			break;
@@ -559,8 +563,8 @@
 {
 	fprintf(stderr,
 		"usage: dump [-0123456789acLnSu] [-B records] [-b blocksize] [-C cachesize]\n"
-		"            [-D dumpdates] [-d density] [-f file] [-h level] [-s feet]\n"
-		"            [-T date] filesystem\n"
+		"            [-D dumpdates] [-d density] [-f file] [-F script] [-h level]\n"
+		"            [-s feet] [-T date] filesystem\n"
 		"       dump -W | -w\n");
 	exit(X_STARTUP);
 }
Only in dump: main.o
Only in dump: optr.o
diff -ru /usr/src/sbin/dump/tape.c dump/tape.c
--- /usr/src/sbin/dump/tape.c	Wed Sep 25 06:06:35 2002
+++ dump/tape.c	Tue Feb  3 23:26:05 2004
@@ -118,6 +118,41 @@
 static jmp_buf jmpbuf;	/* where to jump to if we are ready when the */
 			/* SIGUSR2 arrives from the previous slave */
 
+
+int
+runscript(void)
+{
+	char *cmd;
+	size_t cmd_len;
+	int rc;
+
+	if (script != NULL) {
+		cmd_len = strlen(script) + strlen(disk) + 10;
+		if ((cmd = (char*) malloc(sizeof(char)*cmd_len)) == NULL) {
+			perror("  DUMP: could not allocate memory for command buffer.");
+			return(1);
+		}
+
+		snprintf(cmd, cmd_len, "%s %s %d", script, disk, tapeno);
+		rc = system(cmd);
+
+		if (rc == -1) {
+			perror("  DUMP: execution of script failed");
+			return(1);
+		} else if (rc == (127 << 8)) {
+			msg("Change Volumes: execution of shell failed while running changer script");
+			return(1);
+		} else {
+			msg("Change Volumes: changer script failed with return code %d\n", (rc >> 8));
+			return(1);
+		}
+
+		return(0);
+	}
+
+	return(1);
+}
+
 int
 alloctape(void)
 {
@@ -368,15 +403,17 @@
 	if (nexttape)
 		return;
 	(void)time((time_t *)&(tstart_changevol));
-	if (!nogripe) {
-		msg("Change Volumes: Mount volume #%d\n", tapeno+1);
-		broadcast("CHANGE DUMP VOLUMES!\a\a\n");
-	}
-	while (!query("Is the new volume mounted and ready to go?"))
-		if (query("Do you want to abort?")) {
-			dumpabort(0);
-			/*NOTREACHED*/
+	if (runscript()) {
+		if (!nogripe) {
+			msg("Change Volumes: Mount volume #%d\n", tapeno+1);
+			broadcast("CHANGE DUMP VOLUMES!\a\a\n");
 		}
+		while (!query("Is the new volume mounted and ready to go?"))
+			if (query("Do you want to abort?")) {
+				dumpabort(0);
+				/*NOTREACHED*/
+			}
+	}
 	(void)time((time_t *)&(tend_changevol));
 	if ((tstart_changevol != (time_t)-1) && (tend_changevol != (time_t)-1))
 		tstart_writing += (tend_changevol - tstart_changevol);
Only in dump: tape.c~
Only in dump: tape.o
Only in dump: traverse.o
Only in dump: unctime.o

--Apple-Mail-14-905039896--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3CAA4153-569C-11D8-8876-000A95A9A574>