1 /* Cumulus: Smart Filesystem Backup to Dumb Servers
3 * Copyright (C) 2007-2008 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /* When creating backup snapshots, maintain a local database of data blocks and
22 * checksums, in addition to the data contents (which may be stored remotely).
23 * This database is consulted when attempting to build incremental snapshots,
24 * as it says which objects can be reused.
26 * The database is implemented as an SQLite3 database, but this implementation
27 * detail is kept internal to this file, so that the storage format may be
30 #ifndef _LBS_LOCALDB_H
31 #define _LBS_LOCALDB_H
41 void Open(const char *path, const char *snapshot_name,
42 const char *snapshot_scheme, double intent);
44 void StoreObject(const ObjectReference& ref,
45 const std::string &checksum, int64_t size, double age);
46 ObjectReference FindObject(const std::string &checksum, int64_t size);
47 bool IsOldObject(const std::string &checksum, int64_t size, double *age,
49 bool IsAvailable(const ObjectReference &ref);
50 void UseObject(const ObjectReference& ref);
51 void UseSegment(const std::string &segment, double utilization);
53 void SetSegmentChecksum(const std::string &segment, const std::string &path,
54 const std::string &checksum, int size);
55 bool GetSegmentChecksum(const std::string &segment,
56 std::string *seg_path, std::string *seg_checksum);
58 bool LoadChunkSignatures(ObjectReference ref,
59 void **buf, size_t *len,
60 std::string *algorithm);
61 void StoreChunkSignatures(ObjectReference ref,
62 const void *buf, size_t len,
63 const std::string &algorithm);
68 sqlite3_stmt *Prepare(const char *sql);
69 void ReportError(int rc);
70 int64_t SegmentToId(const std::string &segment);
71 std::string IdToSegment(int64_t segmentid);
74 #endif // _LBS_LOCALDB_H