1 /* LBS: An LFS-inspired filesystem backup system
2 * Copyright (C) 2006 Michael Vrable
4 * Backup data is stored in a collection of objects, which are grouped together
5 * into segments for storage purposes. This implementation of the object store
6 * is built on top of libtar, and represents segments as TAR files and objects
7 * as files within them. */
9 #ifndef _LBS_TARSTORE_H
10 #define _LBS_TARSTORE_H
21 /* A simple wrapper around a single TAR file to represent a segment. Objects
22 * may only be written out all at once, since the tar header must be written
23 * first; incremental writing is not supported. */
26 Tarfile(const std::string &path, const std::string &segment);
29 void write_object(int id, const char *data, size_t len);
32 void internal_write_object(const std::string &path,
33 const char *data, size_t len);
35 std::string segment_name;
36 std::ostringstream checksums;
40 class TarSegmentStore {
42 // New segments will be stored in the given directory.
43 TarSegmentStore(const std::string &path) { this->path = path; }
44 ~TarSegmentStore() { sync(); }
46 // Writes an object to segment in the store, and returns the name
47 // (segment/object) to refer to it. The optional parameter group can be
48 // used to control object placement; objects with different group
49 // parameters are kept in separate segments.
50 std::string write_object(const char *data, size_t len,
51 const std::string &group = "");
53 // Ensure all segments have been fully written.
59 std::string name; // UUID
60 int count; // Objects written to this segment
64 std::map<std::string, struct segment_info *> segments;
67 #endif // _LBS_TARSTORE_H