Enhance the "ctdb restoredb" command so you can restore a backup into a different...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 20 May 2010 01:26:37 +0000 (11:26 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Mon, 24 May 2010 02:34:31 +0000 (12:34 +1000)
tools/ctdb.c

index 0976366bae6a3daba43966432546f34bf88c7e6f..2939f88c57884dc76b9c156865c4c3eccb7921c2 100644 (file)
@@ -3346,8 +3346,9 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
        uint32_t generation;
        struct tm *tm;
        char tbuf[100];
+       char *dbname;
 
-       if (argc != 1) {
+       if (argc < 1 || argc > 2) {
                DEBUG(DEBUG_ERR,("Invalid arguments\n"));
                return -1;
        }
@@ -3366,6 +3367,11 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
                return -1;
        }
 
+       dbname = dbhdr.name;
+       if (argc == 2) {
+               dbname = argv[1];
+       }
+
        outdata.dsize = dbhdr.size;
        outdata.dptr = talloc_size(tmp_ctx, outdata.dsize);
        if (outdata.dptr == NULL) {
@@ -3380,12 +3386,12 @@ static int control_restoredb(struct ctdb_context *ctdb, int argc, const char **a
        tm = localtime(&dbhdr.timestamp);
        strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
        printf("Restoring database '%s' from backup @ %s\n",
-               dbhdr.name, tbuf);
+               dbname, tbuf);
 
 
-       ctdb_db = ctdb_attach(ctdb, dbhdr.name, dbhdr.persistent, 0);
+       ctdb_db = ctdb_attach(ctdb, dbname, dbhdr.persistent, 0);
        if (ctdb_db == NULL) {
-               DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbhdr.name));
+               DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbname));
                talloc_free(tmp_ctx);
                return -1;
        }
@@ -4057,7 +4063,7 @@ static const struct {
        { "delip",           control_delip,             false,  false, "delete an ip address from a node", "<ip>"},
        { "eventscript",     control_eventscript,       true,   false, "run the eventscript with the given parameters on a node", "<arguments>"},
        { "backupdb",        control_backupdb,          false,  false, "backup the database into a file.", "<database> <file>"},
-       { "restoredb",        control_restoredb,        false,  false, "restore the database from a file.", "<file>"},
+       { "restoredb",        control_restoredb,        false,  false, "restore the database from a file.", "<file> [dbname]"},
        { "dumpdbbackup",    control_dumpdbbackup,      false,  true,  "dump database backup from a file.", "<file>"},
        { "wipedb",           control_wipedb,        false,     false, "wipe the contents of a database.", "<dbname>"},
        { "recmaster",        control_recmaster,        false,  false, "show the pnn for the recovery master."},