summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-02-21 16:34:32 +0100
committerJeremy Allison <jra@samba.org>2014-05-22 21:05:14 +0200
commit781563061dbf2b53bc6685cd2db7ace9ee35d280 (patch)
tree7798b67768df6f00c43d48aa66c661e23e7e4db7
parent8935242489fdcc17b20b3cd54f96ba6de5870230 (diff)
downloadsamba-781563061dbf2b53bc6685cd2db7ace9ee35d280.tar.gz
tdb/tools: add -l option to tdbbackup
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>
-rw-r--r--lib/tdb/man/tdbbackup.8.xml12
-rw-r--r--lib/tdb/tools/tdbbackup.c18
2 files changed, 25 insertions, 5 deletions
diff --git a/lib/tdb/man/tdbbackup.8.xml b/lib/tdb/man/tdbbackup.8.xml
index f24202e6877..30a658d3887 100644
--- a/lib/tdb/man/tdbbackup.8.xml
+++ b/lib/tdb/man/tdbbackup.8.xml
@@ -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>
@@ -68,6 +69,17 @@
</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>
diff --git a/lib/tdb/tools/tdbbackup.c b/lib/tdb/tools/tdbbackup.c
index 276a281e46f..eb33e257b4c 100644
--- a/lib/tdb/tools/tdbbackup.c
+++ b/lib/tdb/tools/tdbbackup.c
@@ -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;
}
}