Rename --name to --scheme, and store the scheme name in the local database.
[cumulus.git] / localdb.h
1 /* LBS: An LFS-inspired filesystem backup system
2  * Copyright (C) 2007  Michael Vrable
3  *
4  * When creating backup snapshots, maintain a local database of data blocks and
5  * checksums, in addition to the data contents (which may be stored remotely).
6  * This database is consulted when attempting to build incremental snapshots,
7  * as it says which objects can be reused.
8  *
9  * The database is implemented as an SQLite3 database, but this implementation
10  * detail is kept internal to this file, so that the storage format may be
11  * changed later. */
12
13 #ifndef _LBS_LOCALDB_H
14 #define _LBS_LOCALDB_H
15
16 #include <sqlite3.h>
17
18 #include <string>
19
20 #include "ref.h"
21
22 class LocalDb {
23 public:
24     void Open(const char *path, const char *snapshot_name,
25               const char *snapshot_scheme);
26     void Close();
27     void StoreObject(const ObjectReference& ref,
28                      const std::string &checksum, int64_t size, double age);
29     ObjectReference FindObject(const std::string &checksum, int64_t size);
30     bool IsOldObject(const std::string &checksum, int64_t size, double *age);
31     bool IsAvailable(const ObjectReference &ref);
32     void UseObject(const ObjectReference& ref);
33 private:
34     sqlite3 *db;
35     int64_t snapshotid;
36
37     sqlite3_stmt *Prepare(const char *sql);
38     int64_t SegmentToId(const std::string &segment);
39     std::string IdToSegment(int64_t segmentid);
40 };
41
42 #endif // _LBS_LOCALDB_H