Changeset: 5ac9837ce309 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5ac9837ce309 Modified Files: tools/merovingian/daemon/controlrunner.c tools/merovingian/daemon/snapshot.c tools/merovingian/daemon/snapshot.h Branch: hot-snapshot Log Message:
Snapshot restore, mero daemon side (stub) diffs (126 lines): diff --git a/tools/merovingian/daemon/controlrunner.c b/tools/merovingian/daemon/controlrunner.c --- a/tools/merovingian/daemon/controlrunner.c +++ b/tools/merovingian/daemon/controlrunner.c @@ -733,6 +733,22 @@ static void ctl_handle_client( } free(dest); } + } else if (strncmp(p, "snapshot restore adhoc ", strlen("snapshot restore adhoc ")) == 0) { + char *source = p + strlen("snapshot restore adhoc "); + Mfprintf(_mero_ctlout, "Start restore snapshot of database '%s' from file '%s'\n", q, source); + char *e = snapshot_restore_from(q, source); + if (e != NULL) { + Mfprintf(_mero_ctlerr, "%s: restore database '%s' from snapshot %s failed: %s", + origin, q, source, getErrMsg(e)); + len = snprintf(buf2, sizeof(buf2), "%s\n", getErrMsg(e)); + send_client("!"); + freeErr(e); + } else { + len = snprintf(buf2, sizeof(buf2), "OK\n"); + send_client("="); + Mfprintf(_mero_ctlout, "%s: restored database '%s' from snapshot '%s'\n", + origin, q, source); + } } else if (strncmp(p, "name=", strlen("name=")) == 0) { char *e; diff --git a/tools/merovingian/daemon/snapshot.c b/tools/merovingian/daemon/snapshot.c --- a/tools/merovingian/daemon/snapshot.c +++ b/tools/merovingian/daemon/snapshot.c @@ -19,10 +19,9 @@ #include "mapi.h" #include "snapshot.h" -static err validate_destination(const char *dest); +static err validate_location(const char *path); /* Create a snapshot of database dbname to file dest. - * TODO: verify that dest is a safe location. * TODO: Make it work for databases without monetdb/monetdb root account. */ err @@ -46,7 +45,7 @@ snapshot_database_to(char *dbname, char } /* Do not overwrite random files on the system. */ - e = validate_destination(dest); + e = validate_location(dest); if (e != NO_ERR) { goto bailout; } @@ -89,6 +88,28 @@ bailout: return e; } +/* Restore a database from a snapshot file. + * TODO: Make it work for databases without monetdb/monetdb root account. + */ +err +snapshot_restore_from(char *dbname, char *source) +{ + err e; + (void)dbname; + (void)source; + + /* Do not read random files on the system. */ + e = validate_location(source); + if (e != NO_ERR) { + goto bailout; + } + + e = newErr("not implemented"); + +bailout: + return e; +} + err snapshot_default_filename(char **ret, const char *dbname) { @@ -127,7 +148,7 @@ bailout: static err -validate_destination(const char *dest) +validate_location(const char *dest) { err e = NO_ERR; /* these are malloc'ed: */ @@ -141,7 +162,7 @@ validate_destination(const char *dest) /* Get the canonical path of the snapshot directory */ configured_snapdir = getConfVal(_mero_props, "snapshotdir"); if (configured_snapdir == NULL || configured_snapdir[0] == '\0') { - e = newErr("Snapshot target file not allowed because no 'snapshotdir' has been configured"); + e = newErr("Action not allowed because no 'snapshotdir' has been configured"); goto bailout; } if (configured_snapdir[0] != '/') { @@ -161,7 +182,7 @@ validate_destination(const char *dest) resolved_destination = realpath(dest_dir, NULL); if (resolved_destination == NULL) { - e = newErr("Cannot resolve snapshot target directory '%s': %s", + e = newErr("Cannot resolve snapshot directory '%s': %s", dest_dir, strerror(errno)); goto bailout; } @@ -174,7 +195,7 @@ validate_destination(const char *dest) resolved_destination, strlen(resolved_snapdir)) ) { - e = newErr("Snapshot target '%s' is not inside configured snapshot directory '%s'", + e = newErr("Snapshot directory '%s' is not inside configured snapshot directory '%s'", dest, resolved_snapdir); goto bailout; } diff --git a/tools/merovingian/daemon/snapshot.h b/tools/merovingian/daemon/snapshot.h --- a/tools/merovingian/daemon/snapshot.h +++ b/tools/merovingian/daemon/snapshot.h @@ -12,6 +12,7 @@ #include "merovingian.h" err snapshot_database_to(char *dname, char *dest); +err snapshot_restore_from(char *dname, char *source); err snapshot_default_filename(char **filename_buf, const char *dbname); #endif _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list