tdb/tools: add -l option to tdbbackup
authorVolker Lendecke <vl@samba.org>
Thu, 21 Feb 2013 15:34:32 +0000 (16:34 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 22 May 2014 19:05:14 +0000 (21:05 +0200)
This opens the tdb with TDB_NOLOCK.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/tdb/man/tdbbackup.8.xml
lib/tdb/tools/tdbbackup.c

index f24202e6877638da644894e14ccd702226e852d7..30a658d3887513695314b8248b1d61bea81c048b 100644 (file)
@@ -22,6 +22,7 @@
                <arg choice="opt">-s suffix</arg>
                <arg choice="opt">-v</arg>
                <arg choice="opt">-h</arg>
+               <arg choice="opt">-l</arg>
        </cmdsynopsis>
 </refsynopsisdiv>
 
                </para></listitem>
                </varlistentry>
 
+               <varlistentry>
+               <term>-l</term>
+               <listitem><para>
+               This options disables any locking, by passing TDB_NOLOCK
+               to tdb_open_ex(). Only use this for database files which
+               are not used by any other process! And also only if it is otherwise not
+               possible to open the database, e.g. databases which were created with
+               mutex locking.
+               </para></listitem>
+               </varlistentry>
+
        </variablelist>
 </refsect1>
 
index 276a281e46f2f6f5e1d914ef58c481fa0ef39179..eb33e257b4c4dbf8348c27cbbf6d41bf2274f77f 100644 (file)
@@ -104,7 +104,8 @@ static int test_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
   only doing the backup if its OK
   this function is also used for restore
 */
-static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
+static int backup_tdb(const char *old_name, const char *new_name,
+                     int hash_size, int nolock)
 {
        TDB_CONTEXT *tdb;
        TDB_CONTEXT *tdb_new;
@@ -122,7 +123,8 @@ static int backup_tdb(const char *old_name, const char *new_name, int hash_size)
        }
 
        /* open the old tdb */
-       tdb = tdb_open_ex(old_name, 0, 0,
+       tdb = tdb_open_ex(old_name, 0,
+                         TDB_DEFAULT | (nolock ? TDB_NOLOCK : 0),
                          O_RDWR, 0, &log_ctx, NULL);
        if (!tdb) {
                printf("Failed to open %s\n", old_name);
@@ -249,7 +251,7 @@ static int verify_tdb(const char *fname, const char *bak_name)
        /* count is < 0 means an error */
        if (count < 0) {
                printf("restoring %s\n", fname);
-               return backup_tdb(bak_name, fname, 0);
+               return backup_tdb(bak_name, fname, 0, 0);
        }
 
        printf("%s : %d records\n", fname, count);
@@ -279,6 +281,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("   -l            open without locking to back up mutex dbs\n");
 }
 
  int main(int argc, char *argv[])
@@ -288,11 +291,12 @@ static void usage(void)
        int c;
        int verify = 0;
        int hashsize = 0;
+       int nolock = 0;
        const char *suffix = ".bak";
 
        log_ctx.log_fn = tdb_log;
 
-       while ((c = getopt(argc, argv, "vhs:n:")) != -1) {
+       while ((c = getopt(argc, argv, "vhs:n:l")) != -1) {
                switch (c) {
                case 'h':
                        usage();
@@ -306,6 +310,9 @@ static void usage(void)
                case 'n':
                        hashsize = atoi(optarg);
                        break;
+               case 'l':
+                       nolock = 1;
+                       break;
                }
        }
 
@@ -329,7 +336,8 @@ static void usage(void)
                        }
                } else {
                        if (file_newer(fname, bak_name) &&
-                           backup_tdb(fname, bak_name, hashsize) != 0) {
+                           backup_tdb(fname, bak_name, hashsize,
+                                      nolock) != 0) {
                                ret = 1;
                        }
                }