#include <list>
#include <vector>
#include <iostream>
+#include <fstream>
#include <sstream>
#include <set>
static TarSegmentStore *tss = NULL;
/* Buffer for holding a single block of data read from a file. */
-static const int LBS_BLOCK_SIZE = 1024 * 1024;
+static const size_t LBS_BLOCK_SIZE = 1024 * 1024;
static char *block_buf;
-static const int LBS_METADATA_BLOCK_SIZE = 65536;
+static const size_t LBS_METADATA_BLOCK_SIZE = 65536;
/* Contents of the root object. This will contain a set of indirect links to
* the metadata objects. */
list<string> object_list;
if ((stat_buf.st_mode & S_IFMT) != S_IFREG) {
- printf("file is no longer a regular file!\n");
+ fprintf(stderr, "file is no longer a regular file!\n");
return;
}
buf = new char[stat_buf.st_size + 2];
len = readlink(path.c_str(), buf, stat_buf.st_size + 1);
if (len < 0) {
- printf("error reading symlink: %m\n");
+ fprintf(stderr, "error reading symlink: %m\n");
} else if (len <= stat_buf.st_size) {
buf[len] = '\0';
- printf(" contents=%s\n", buf);
+ file_info["contents"] = uri_encode(buf);
} else if (len > stat_buf.st_size) {
- printf("error reading symlink: name truncated\n");
+ fprintf(stderr, "error reading symlink: name truncated\n");
}
- file_info["contents"] = uri_encode(buf);
-
delete[] buf;
break;
case S_IFREG:
DIR *dir = opendir(path.c_str());
if (dir == NULL) {
- printf("Error: %m\n");
+ fprintf(stderr, "Error: %m\n");
return;
}
{
block_buf = new char[LBS_BLOCK_SIZE];
- if (argc > 1) {
- tss = new TarSegmentStore(argv[1]);
- } else {
- tss = new TarSegmentStore(".");
- }
+ string backup_dest = ".";
+
+ if (argc > 1)
+ backup_dest = argv[1];
+
+ tss = new TarSegmentStore(backup_dest);
+
+ /* Write a backup descriptor file, which says which segments are needed and
+ * where to start to restore this snapshot. The filename is based on the
+ * current time. */
+ time_t now;
+ struct tm time_buf;
+ char desc_buf[256];
+ time(&now);
+ localtime_r(&now, &time_buf);
+ strftime(desc_buf, sizeof(desc_buf), "%Y%m%dT%H%M%S", &time_buf);
+ string desc_filename = backup_dest + "/" + desc_buf + ".lbs";
+ std::ofstream descriptor(desc_filename.c_str());
try {
scanfile(".");
root->checksum();
segment_list.insert(root->get_ref().get_segment());
- string r = root->get_ref().to_string();
- printf("\nroot: %s\n\n", r.c_str());
+ descriptor << "root: " << root->get_ref().to_string() << "\n";
+ strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z", &time_buf);
+ descriptor << "time: " << desc_buf << "\n";
+
delete root;
- printf("segments:\n");
+ descriptor << "segments:\n";
for (std::set<string>::iterator i = segment_list.begin();
i != segment_list.end(); ++i) {
- printf(" %s\n", i->c_str());
+ descriptor << " " << *i << "\n";
}
tss->sync();