From: Michael Vrable Date: Fri, 20 Jul 2007 16:59:32 +0000 (-0700) Subject: Rename --name to --scheme, and store the scheme name in the local database. X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=def20364a3596d7b1fa4a07f3d3ee056cfff2d1e;p=cumulus.git Rename --name to --scheme, and store the scheme name in the local database. --- diff --git a/localdb.cc b/localdb.cc index bc2bc69..9ec0c96 100644 --- a/localdb.cc +++ b/localdb.cc @@ -38,7 +38,8 @@ sqlite3_stmt *LocalDb::Prepare(const char *sql) return stmt; } -void LocalDb::Open(const char *path, const char *snapshot_name) +void LocalDb::Open(const char *path, const char *snapshot_name, + const char *snapshot_scheme) { int rc; @@ -58,10 +59,16 @@ void LocalDb::Open(const char *path, const char *snapshot_name) /* Insert this snapshot into the database, and determine the integer key * which will be used to identify it. */ - sqlite3_stmt *stmt = Prepare("insert into snapshots(name, timestamp) " - "values (?, julianday('now'))"); + sqlite3_stmt *stmt = Prepare("insert into " + "snapshots(name, scheme, timestamp) " + "values (?, ?, julianday('now'))"); sqlite3_bind_text(stmt, 1, snapshot_name, strlen(snapshot_name), SQLITE_TRANSIENT); + if (snapshot_scheme == NULL) + sqlite3_bind_null(stmt, 2); + else + sqlite3_bind_text(stmt, 2, snapshot_scheme, strlen(snapshot_scheme), + SQLITE_TRANSIENT); rc = sqlite3_step(stmt); if (rc != SQLITE_DONE) { diff --git a/localdb.h b/localdb.h index 4654b37..0fce30d 100644 --- a/localdb.h +++ b/localdb.h @@ -21,7 +21,8 @@ class LocalDb { public: - void Open(const char *path, const char *snapshot_name); + void Open(const char *path, const char *snapshot_name, + const char *snapshot_scheme); void Close(); void StoreObject(const ObjectReference& ref, const std::string &checksum, int64_t size, double age); diff --git a/scandir.cc b/scandir.cc index ca14cfc..4ffd078 100644 --- a/scandir.cc +++ b/scandir.cc @@ -555,7 +555,7 @@ void usage(const char *program) " --filter-extension=EXT\n" " string to append to segment files\n" " (defaults to \".bz2\")\n" - " --name=NAME optional name for this snapshot\n", + " --scheme=NAME optional name for this snapshot\n", program ); } @@ -565,7 +565,7 @@ int main(int argc, char *argv[]) string backup_source = "."; string backup_dest = ""; string localdb_dir = ""; - string backup_name = ""; + string backup_scheme = ""; while (1) { static struct option long_options[] = { @@ -574,7 +574,7 @@ int main(int argc, char *argv[]) {"filter", 1, 0, 0}, // 2 {"filter-extension", 1, 0, 0}, // 3 {"dest", 1, 0, 0}, // 4 - {"name", 1, 0, 0}, // 5 + {"scheme", 1, 0, 0}, // 5 {NULL, 0, 0, 0}, }; @@ -604,8 +604,8 @@ int main(int argc, char *argv[]) case 4: // --dest backup_dest = optarg; break; - case 5: // --name - backup_name = optarg; + case 5: // --scheme + backup_scheme = optarg; break; default: fprintf(stderr, "Unhandled long option!\n"); @@ -683,7 +683,8 @@ int main(int argc, char *argv[]) * snapshot. */ string database_path = localdb_dir + "/localdb.sqlite"; db = new LocalDb; - db->Open(database_path.c_str(), desc_buf); + db->Open(database_path.c_str(), desc_buf, + backup_scheme.size() ? backup_scheme.c_str() : NULL); /* Initialize the stat cache, for skipping over unchanged files. */ statcache = new StatCache; @@ -717,8 +718,8 @@ int main(int argc, char *argv[]) * where to start to restore this snapshot. The filename is based on the * current time. */ string desc_filename = backup_dest + "/snapshot-"; - if (backup_name.size() > 0) - desc_filename += backup_name + "-"; + if (backup_scheme.size() > 0) + desc_filename += backup_scheme + "-"; desc_filename = desc_filename + desc_buf + ".lbs"; std::ofstream descriptor(desc_filename.c_str()); @@ -726,8 +727,8 @@ int main(int argc, char *argv[]) descriptor << "Producer: LBS " << lbs_version << "\n"; strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z", &time_buf); descriptor << "Date: " << desc_buf << "\n"; - if (backup_name.size() > 0) - descriptor << "Name: " << backup_name << "\n"; + if (backup_scheme.size() > 0) + descriptor << "Scheme: " << backup_scheme << "\n"; descriptor << "Root: " << backup_root << "\n"; descriptor << "Segments:\n"; diff --git a/schema.sql b/schema.sql index 1a7e5ee..6d89b4b 100644 --- a/schema.sql +++ b/schema.sql @@ -7,6 +7,7 @@ create table snapshots ( snapshotid integer primary key, name text not null, + scheme text, timestamp real );