New feature for tdbbackup: check status (verify but don't restore)

Volodymyr Khomenko Volodymyr.Khomenko at exanet.com
Thu Nov 13 09:41:54 GMT 2008


>> You might want to resend the patch in "git format-patch"
>> format.

>From 76542d0c3327c6c30bd8f4d26b0962875ec8ca99 Mon Sep 17 00:00:00 2001
From: Volodymyr Khomenko <Volodymyr.Khomenko at exanet.com>
Date: Thu, 13 Nov 2008 11:36:59 +0200
Subject: [PATCH] New feature for tdbbackup: check status (verify but don't restore)

---
 source/lib/tdb/tools/tdbbackup.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/source/lib/tdb/tools/tdbbackup.c b/source/lib/tdb/tools/tdbbackup.c
index 6f3ca48..267f8fa 100644
--- a/source/lib/tdb/tools/tdbbackup.c
+++ b/source/lib/tdb/tools/tdbbackup.c
@@ -190,9 +190,11 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
 }
 
 /*
-  verify a tdb and if it is corrupt then restore from *.bak
+  verify a tdb and if it is corrupt then
+  -restore from *.bak (if dont_restore is not set)
+  -do nothing, just return negative value; bak_name will not be used (if dont_restore is set)
 */
-static int verify_tdb(const char *fname, const char *bak_name)
+static int verify_tdb(const char *fname, const char *bak_name, int dont_restore)
 {
 	TDB_CONTEXT *tdb;
 	int count = -1;
@@ -208,6 +210,8 @@ static int verify_tdb(const char *fname, const char *bak_name)
 
 	/* count is < 0 means an error */
 	if (count < 0) {
+		if(dont_restore)
+			return count;
 		printf("restoring %s\n", fname);
 		return backup_tdb(bak_name, fname, 0);
 	}
@@ -239,6 +243,7 @@ static void usage(void)
 	printf("   -s suffix     set the backup suffix\n");
 	printf("   -v            verify mode (restore if corrupt)\n");
 	printf("   -n hashsize   set the new hash size for the backup\n");
+	printf("   -c            check status (do not restore if corrupt)\n");
 }
 		
 
@@ -249,9 +254,10 @@ static void usage(void)
 	int c;
 	int verify = 0;
 	int hashsize = 0;
+	int check_status = 0;
 	const char *suffix = ".bak";
 
-	while ((c = getopt(argc, argv, "vhs:n:")) != -1) {
+	while ((c = getopt(argc, argv, "vhs:n:c")) != -1) {
 		switch (c) {
 		case 'h':
 			usage();
@@ -265,6 +271,9 @@ static void usage(void)
 		case 'n':
 			hashsize = atoi(optarg);
 			break;
+		case 'c':
+			check_status = 1;
+			break;
 		}
 	}
 
@@ -282,14 +291,20 @@ static void usage(void)
 
 		bak_name = add_suffix(fname, suffix);
 
-		if (verify) {
-			if (verify_tdb(fname, bak_name) != 0) {
+		if(check_status) {
+			if (verify_tdb(fname, NULL, 1) != 0) {
 				ret = 1;
 			}
 		} else {
-			if (file_newer(fname, bak_name) &&
-			    backup_tdb(fname, bak_name, hashsize) != 0) {
-				ret = 1;
+			if (verify) {
+				if (verify_tdb(fname, bak_name, 0) != 0) {
+					ret = 1;
+				}
+			} else {
+				if (file_newer(fname, bak_name) &&
+					backup_tdb(fname, bak_name, hashsize) != 0) {
+					ret = 1;
+				}
 			}
 		}
 
-- 
1.5.4.5

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-New-feature-for-tdbbackup-check-status-verify-but.patch
Type: application/octet-stream
Size: 2744 bytes
Desc: 0001-New-feature-for-tdbbackup-check-status-verify-but.patch
Url : http://lists.samba.org/archive/samba-technical/attachments/20081113/5006eff4/0001-New-feature-for-tdbbackup-check-status-verify-but.obj


More information about the samba-technical mailing list