1 /* Cumulus: Smart Filesystem Backup to Dumb Servers
3 * Copyright (C) 2006-2009 The Regents of the University of California
4 * Copyright (C) 2012 Google Inc.
5 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /* Main entry point for Cumulus. Contains logic for traversing the filesystem
23 * and constructing a backup. */
36 #include <sys/sysmacros.h>
37 #include <sys/types.h>
58 #include "third_party/sha1.h"
66 /* Version information. This will be filled in by the Makefile. */
67 #ifndef CUMULUS_VERSION
68 #define CUMULUS_VERSION Unknown
70 #define CUMULUS_STRINGIFY(s) CUMULUS_STRINGIFY2(s)
71 #define CUMULUS_STRINGIFY2(s) #s
72 static const char cumulus_version[] = CUMULUS_STRINGIFY(CUMULUS_VERSION);
74 static RemoteStore *remote = NULL;
75 static TarSegmentStore *tss = NULL;
76 static MetadataWriter *metawriter = NULL;
78 /* Buffer for holding a single block of data read from a file. */
79 static const size_t LBS_BLOCK_SIZE = 1024 * 1024;
80 static char *block_buf;
82 /* Local database, which tracks objects written in this and previous
83 * invocations to help in creating incremental snapshots. */
86 /* Keep track of all segments which are needed to reconstruct the snapshot. */
87 std::set<string> segment_list;
89 /* Snapshot intent: 1=daily, 7=weekly, etc. This is not used directly, but is
90 * stored in the local database and can help guide segment cleaning and
91 * snapshot expiration policies. */
92 double snapshot_intent = 1.0;
94 /* Selection of files to include/exclude in the snapshot. */
95 PathFilterList filter_rules;
97 bool flag_rebuild_statcache = false;
99 /* Whether verbose output is enabled. */
100 bool verbose = false;
102 /* Ensure that the given segment is listed as a dependency of the current
104 void add_segment(const string& segment)
106 segment_list.insert(segment);
109 /* Attempts to open a regular file read-only, but with safety checks for files
110 * that might not be fully trusted. */
111 int safe_open(const string& path, struct stat *stat_buf)
115 /* Be paranoid when opening the file. We have no guarantee that the
116 * file was not replaced between the stat() call above and the open()
117 * call below, so we might not even be opening a regular file. We
118 * supply flags to open to to guard against various conditions before
119 * we can perform an lstat to check that the file is still a regular
121 * - O_NOFOLLOW: in the event the file was replaced by a symlink
122 * - O_NONBLOCK: prevents open() from blocking if the file was
124 * We also add in O_NOATIME, since this may reduce disk writes (for
125 * inode updates). However, O_NOATIME may result in EPERM, so if the
126 * initial open fails, try again without O_NOATIME. */
127 fd = open(path.c_str(), O_RDONLY|O_NOATIME|O_NOFOLLOW|O_NONBLOCK);
129 fd = open(path.c_str(), O_RDONLY|O_NOFOLLOW|O_NONBLOCK);
132 fprintf(stderr, "Unable to open file %s: %m\n", path.c_str());
136 /* Drop the use of the O_NONBLOCK flag; we only wanted that for file
138 long flags = fcntl(fd, F_GETFL);
139 fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
141 /* Re-check file attributes, storing them into stat_buf if that is
143 struct stat internal_stat_buf;
144 if (stat_buf == NULL)
145 stat_buf = &internal_stat_buf;
147 /* Perform the stat call again, and check that we still have a regular
149 if (fstat(fd, stat_buf) < 0) {
150 fprintf(stderr, "fstat: %m\n");
155 if ((stat_buf->st_mode & S_IFMT) != S_IFREG) {
156 fprintf(stderr, "file is no longer a regular file!\n");
164 /* Read data from a file descriptor and return the amount of data read. A
165 * short read (less than the requested size) will only occur if end-of-file is
167 ssize_t file_read(int fd, char *buf, size_t maxlen)
169 size_t bytes_read = 0;
172 ssize_t res = read(fd, buf, maxlen);
176 fprintf(stderr, "error reading file: %m\n");
178 } else if (res == 0) {
190 /* Read the contents of a file (specified by an open file descriptor) and copy
191 * the data to the store. Returns the size of the file (number of bytes
192 * dumped), or -1 on error. */
193 int64_t dumpfile(int fd, dictionary &file_info, const string &path,
194 struct stat& stat_buf)
197 list<string> object_list;
198 const char *status = NULL; /* Status indicator printed out */
200 /* Look up this file in the old stat cache, if we can. If the stat
201 * information indicates that the file has not changed, do not bother
202 * re-reading the entire contents. Even if the information has been
203 * changed, we can use the list of old blocks in the search for a sub-block
204 * incremental representation. */
206 list<ObjectReference> old_blocks;
208 bool found = metawriter->find(path);
210 old_blocks = metawriter->get_blocks();
213 && !flag_rebuild_statcache
214 && metawriter->is_unchanged(&stat_buf)) {
217 /* If any of the blocks in the object have been expired, then we should
218 * fall back to fully reading in the file. */
219 for (list<ObjectReference>::const_iterator i = old_blocks.begin();
220 i != old_blocks.end(); ++i) {
221 const ObjectReference &ref = *i;
222 if (!db->IsAvailable(ref)) {
229 /* If everything looks okay, use the cached information */
231 file_info["checksum"] = metawriter->get_checksum();
232 for (list<ObjectReference>::const_iterator i = old_blocks.begin();
233 i != old_blocks.end(); ++i) {
234 const ObjectReference &ref = *i;
235 object_list.push_back(ref.to_string());
237 add_segment(ref.get_segment());
240 size = stat_buf.st_size;
244 /* If the file is new or changed, we must read in the contents a block at a
249 subfile.load_old_blocks(old_blocks);
252 ssize_t bytes = file_read(fd, block_buf, LBS_BLOCK_SIZE);
256 fprintf(stderr, "Backup contents for %s may be incorrect\n",
261 hash.process(block_buf, bytes);
263 // Sparse file processing: if we read a block of all zeroes, encode
265 bool all_zero = true;
266 for (int i = 0; i < bytes; i++) {
267 if (block_buf[i] != 0) {
273 // Either find a copy of this block in an already-existing segment,
274 // or index it so it can be re-used in the future
275 double block_age = 0.0;
278 SHA1Checksum block_hash;
279 block_hash.process(block_buf, bytes);
280 string block_csum = block_hash.checksum_str();
283 ref = ObjectReference(ObjectReference::REF_ZERO);
284 ref.set_range(0, bytes);
286 ref = db->FindObject(block_csum, bytes);
289 list<ObjectReference> refs;
291 // Store a copy of the object if one does not yet exist
293 LbsObject *o = new LbsObject;
296 /* We might still have seen this checksum before, if the object
297 * was stored at some time in the past, but we have decided to
298 * clean the segment the object was originally stored in
299 * (FindObject will not return such objects). When rewriting
300 * the object contents, put it in a separate group, so that old
301 * objects get grouped together. The hope is that these old
302 * objects will continue to be used in the future, and we
303 * obtain segments which will continue to be well-utilized.
304 * Additionally, keep track of the age of the data by looking
305 * up the age of the block which was expired and using that
306 * instead of the current time. */
307 if (db->IsOldObject(block_csum, bytes,
308 &block_age, &object_group)) {
309 if (object_group == 0) {
310 o->set_group("data");
313 sprintf(group, "compacted-%d", object_group);
319 o->set_group("data");
323 subfile.analyze_new_block(block_buf, bytes);
324 refs = subfile.create_incremental(tss, o, block_age);
326 if (flag_rebuild_statcache && ref.is_normal()) {
327 subfile.analyze_new_block(block_buf, bytes);
328 subfile.store_analyzed_signatures(ref);
333 while (!refs.empty()) {
334 ref = refs.front(); refs.pop_front();
335 object_list.push_back(ref.to_string());
337 add_segment(ref.get_segment());
346 file_info["checksum"] = hash.checksum_str();
349 // Sanity check: if we are rebuilding the statcache, but the file looks
350 // like it hasn't changed, then the newly-computed checksum should match
351 // the checksum in the statcache. If not, we have possible disk corruption
352 // and report a warning.
353 if (flag_rebuild_statcache) {
355 && metawriter->is_unchanged(&stat_buf)
356 && file_info["checksum"] != metawriter->get_checksum()) {
358 "Warning: Checksum for %s does not match expected value\n"
362 metawriter->get_checksum().c_str(),
363 file_info["checksum"].c_str());
367 if (verbose && status != NULL)
368 printf(" [%s]\n", status);
370 string blocklist = "";
371 for (list<string>::iterator i = object_list.begin();
372 i != object_list.end(); ++i) {
373 if (i != object_list.begin())
377 file_info["data"] = blocklist;
382 /* Look up a user/group and convert it to string form (either strictly numeric
383 * or numeric plus symbolic). Caches the results of the call to
384 * getpwuid/getgrgid. */
385 string user_to_string(uid_t uid) {
386 static map<uid_t, string> user_cache;
387 map<uid_t, string>::const_iterator i = user_cache.find(uid);
388 if (i != user_cache.end())
391 string result = encode_int(uid);
392 struct passwd *pwd = getpwuid(uid);
393 if (pwd != NULL && pwd->pw_name != NULL) {
394 result += " (" + uri_encode(pwd->pw_name) + ")";
396 user_cache[uid] = result;
400 string group_to_string(gid_t gid) {
401 static map<gid_t, string> group_cache;
402 map<gid_t, string>::const_iterator i = group_cache.find(gid);
403 if (i != group_cache.end())
406 string result = encode_int(gid);
407 struct group *grp = getgrgid(gid);
408 if (grp != NULL && grp->gr_name != NULL) {
409 result += " (" + uri_encode(grp->gr_name) + ")";
411 group_cache[gid] = result;
415 /* Dump a specified filesystem object (file, directory, etc.) based on its
416 * inode information. If the object is a regular file, an open filehandle is
418 void dump_inode(const string& path, // Path within snapshot
419 const string& fullpath, // Path to object in filesystem
420 struct stat& stat_buf, // Results of stat() call
421 int fd) // Open filehandle if regular file
424 dictionary file_info;
429 printf("%s\n", path.c_str());
430 metawriter->find(path);
432 file_info["name"] = uri_encode(path);
433 file_info["mode"] = encode_int(stat_buf.st_mode & 07777, 8);
434 file_info["ctime"] = encode_int(stat_buf.st_ctime);
435 file_info["mtime"] = encode_int(stat_buf.st_mtime);
436 file_info["user"] = user_to_string(stat_buf.st_uid);
437 file_info["group"] = group_to_string(stat_buf.st_gid);
439 time_t now = time(NULL);
440 if (now - stat_buf.st_ctime < 30 || now - stat_buf.st_mtime < 30)
441 if ((stat_buf.st_mode & S_IFMT) != S_IFDIR)
442 file_info["volatile"] = "1";
444 if (stat_buf.st_nlink > 1 && (stat_buf.st_mode & S_IFMT) != S_IFDIR) {
445 file_info["links"] = encode_int(stat_buf.st_nlink);
448 file_info["inode"] = encode_int(major(stat_buf.st_dev))
449 + "/" + encode_int(minor(stat_buf.st_dev))
450 + "/" + encode_int(stat_buf.st_ino);
454 switch (stat_buf.st_mode & S_IFMT) {
463 inode_type = ((stat_buf.st_mode & S_IFMT) == S_IFBLK) ? 'b' : 'c';
464 file_info["device"] = encode_int(major(stat_buf.st_rdev))
465 + "/" + encode_int(minor(stat_buf.st_rdev));
470 /* Use the reported file size to allocate a buffer large enough to read
471 * the symlink. Allocate slightly more space, so that we ask for more
472 * bytes than we expect and so check for truncation. */
473 buf = new char[stat_buf.st_size + 2];
474 len = readlink(fullpath.c_str(), buf, stat_buf.st_size + 1);
476 fprintf(stderr, "error reading symlink: %m\n");
477 } else if (len <= stat_buf.st_size) {
479 file_info["target"] = uri_encode(buf);
480 } else if (len > stat_buf.st_size) {
481 fprintf(stderr, "error reading symlink: name truncated\n");
489 file_size = dumpfile(fd, file_info, path, stat_buf);
490 file_info["size"] = encode_int(file_size);
493 return; // error occurred; do not dump file
495 if (file_size != stat_buf.st_size) {
496 fprintf(stderr, "Warning: Size of %s changed during reading\n",
498 file_info["volatile"] = "1";
507 fprintf(stderr, "Unknown inode type: mode=%x\n", stat_buf.st_mode);
511 file_info["type"] = string(1, inode_type);
513 metawriter->add(file_info);
516 /* Converts a path to the normalized form used in the metadata log. Paths are
517 * written as relative (without any leading slashes). The root directory is
518 * referred to as ".". */
519 string metafile_path(const string& path)
521 const char *newpath = path.c_str();
524 if (*newpath == '\0')
529 void try_merge_filter(const string& path, const string& basedir)
531 struct stat stat_buf;
532 if (lstat(path.c_str(), &stat_buf) < 0)
534 if ((stat_buf.st_mode & S_IFMT) != S_IFREG)
536 int fd = safe_open(path, NULL);
540 /* As a very crude limit on the complexity of merge rules, only read up to
541 * one block (1 MB) worth of data. If the file doesn't seems like it might
542 * be larger than that, don't parse the rules in it. */
543 ssize_t bytes = file_read(fd, block_buf, LBS_BLOCK_SIZE);
545 if (bytes < 0 || bytes >= static_cast<ssize_t>(LBS_BLOCK_SIZE - 1)) {
546 /* TODO: Add more strict resource limits on merge files? */
548 "Unable to read filter merge file (possibly size too large\n");
551 filter_rules.merge_patterns(metafile_path(path), basedir,
552 string(block_buf, bytes));
555 void scanfile(const string& path)
558 struct stat stat_buf;
561 string output_path = metafile_path(path);
563 if (lstat(path.c_str(), &stat_buf) < 0) {
564 fprintf(stderr, "lstat(%s): %m\n", path.c_str());
568 bool is_directory = ((stat_buf.st_mode & S_IFMT) == S_IFDIR);
569 if (!filter_rules.is_included(output_path, is_directory))
572 if ((stat_buf.st_mode & S_IFMT) == S_IFREG) {
573 fd = safe_open(path, &stat_buf);
578 dump_inode(output_path, path, stat_buf, fd);
583 /* If we hit a directory, now that we've written the directory itself,
584 * recursively scan the directory. */
586 DIR *dir = opendir(path.c_str());
589 fprintf(stderr, "Error reading directory %s: %m\n",
595 vector<string> contents;
596 while ((ent = readdir(dir)) != NULL) {
597 string filename(ent->d_name);
598 if (filename == "." || filename == "..")
600 contents.push_back(filename);
605 sort(contents.begin(), contents.end());
609 /* First pass through the directory items: look for any filter rules to
610 * merge and do so. */
611 for (vector<string>::iterator i = contents.begin();
612 i != contents.end(); ++i) {
616 else if (path == "/")
619 filename = path + "/" + *i;
620 if (filter_rules.is_mergefile(metafile_path(filename))) {
622 printf("Merging directory filter rules %s\n",
625 try_merge_filter(filename, output_path);
629 /* Second pass: recursively scan all items in the directory for backup;
630 * scanfile() will check if the item should be included or not. */
631 for (vector<string>::iterator i = contents.begin();
632 i != contents.end(); ++i) {
633 const string& filename = *i;
636 else if (path == "/")
637 scanfile("/" + filename);
639 scanfile(path + "/" + filename);
642 filter_rules.restore();
646 void usage(const char *program)
651 "Usage: %s [OPTION]... --dest=DEST PATHS...\n"
652 "Produce backup snapshot of files in SOURCE and store to DEST.\n"
655 " --dest=PATH path where backup is to be written\n"
656 " --upload-script=COMMAND\n"
657 " program to invoke for each backup file generated\n"
658 " --exclude=PATTERN exclude files matching PATTERN from snapshot\n"
659 " --include=PATTERN include files matching PATTERN in snapshot\n"
660 " --dir-merge=PATTERN parse files matching PATTERN to read additional\n"
661 " subtree-specific include/exclude rules during backup\n"
662 " --localdb=PATH local backup metadata is stored in PATH\n"
663 " --tmpdir=PATH path for temporarily storing backup files\n"
664 " (defaults to TMPDIR environment variable or /tmp)\n"
665 " --filter=COMMAND program through which to filter segment data\n"
666 " (defaults to \"bzip2 -c\")\n"
667 " --filter-extension=EXT\n"
668 " string to append to segment files\n"
669 " (defaults to \".bz2\")\n"
670 " --signature-filter=COMMAND\n"
671 " program though which to filter descriptor\n"
672 " --scheme=NAME optional name for this snapshot\n"
673 " --intent=FLOAT intended backup type: 1=daily, 7=weekly, ...\n"
674 " (defaults to \"1\")\n"
675 " --full-metadata do not re-use metadata from previous backups\n"
676 " --rebuild-statcache re-read all file data to verify statcache\n"
677 " -v --verbose list files as they are backed up\n"
679 "Exactly one of --dest or --upload-script must be specified.\n",
680 cumulus_version, program
684 int main(int argc, char *argv[])
686 string backup_dest = "", backup_script = "";
687 string localdb_dir = "";
688 string backup_scheme = "";
689 string signature_filter = "";
691 string tmp_dir = "/tmp";
692 if (getenv("TMPDIR") != NULL)
693 tmp_dir = getenv("TMPDIR");
696 static struct option long_options[] = {
697 {"localdb", 1, 0, 0}, // 0
698 {"filter", 1, 0, 0}, // 1
699 {"filter-extension", 1, 0, 0}, // 2
700 {"dest", 1, 0, 0}, // 3
701 {"scheme", 1, 0, 0}, // 4
702 {"signature-filter", 1, 0, 0}, // 5
703 {"intent", 1, 0, 0}, // 6
704 {"full-metadata", 0, 0, 0}, // 7
705 {"tmpdir", 1, 0, 0}, // 8
706 {"upload-script", 1, 0, 0}, // 9
707 {"rebuild-statcache", 0, 0, 0}, // 10
708 {"include", 1, 0, 0}, // 11
709 {"exclude", 1, 0, 0}, // 12
710 {"dir-merge", 1, 0, 0}, // 13
711 // Aliases for short options
712 {"verbose", 0, 0, 'v'},
717 int c = getopt_long(argc, argv, "v", long_options, &long_index);
723 switch (long_index) {
725 localdb_dir = optarg;
728 filter_program = optarg;
730 case 2: // --filter-extension
731 filter_extension = optarg;
734 backup_dest = optarg;
737 backup_scheme = optarg;
739 case 5: // --signature-filter
740 signature_filter = optarg;
743 snapshot_intent = atof(optarg);
744 if (snapshot_intent <= 0)
747 case 7: // --full-metadata
748 flag_full_metadata = true;
753 case 9: // --upload-script
754 backup_script = optarg;
756 case 10: // --rebuild-statcache
757 flag_rebuild_statcache = true;
759 case 11: // --include
760 filter_rules.add_pattern(PathFilterList::INCLUDE, optarg, "");
762 case 12: // --exclude
763 filter_rules.add_pattern(PathFilterList::EXCLUDE, optarg, "");
765 case 13: // --dir-merge
766 filter_rules.add_pattern(PathFilterList::DIRMERGE, optarg, "");
769 fprintf(stderr, "Unhandled long option!\n");
784 if (optind == argc) {
789 if (backup_dest == "" && backup_script == "") {
791 "Error: Backup destination must be specified using --dest= or --upload-script=\n");
796 if (backup_dest != "" && backup_script != "") {
798 "Error: Cannot specify both --dest= and --upload-script=\n");
803 // Default for --localdb is the same as --dest
804 if (localdb_dir == "") {
805 localdb_dir = backup_dest;
807 if (localdb_dir == "") {
809 "Error: Must specify local database path with --localdb=\n");
814 block_buf = new char[LBS_BLOCK_SIZE];
816 /* Initialize the remote storage layer. If using an upload script, create
817 * a temporary directory for staging files. Otherwise, write backups
818 * directly to the destination directory. */
819 if (backup_script != "") {
820 tmp_dir = tmp_dir + "/lbs." + generate_uuid();
821 if (mkdir(tmp_dir.c_str(), 0700) < 0) {
822 fprintf(stderr, "Cannot create temporary directory %s: %m\n",
826 remote = new RemoteStore(tmp_dir, backup_script=backup_script);
828 remote = new RemoteStore(backup_dest);
831 /* Store the time when the backup started, so it can be included in the
834 struct tm time_buf_local, time_buf_utc;
837 localtime_r(&now, &time_buf_local);
838 gmtime_r(&now, &time_buf_utc);
839 strftime(desc_buf, sizeof(desc_buf), "%Y%m%dT%H%M%S", &time_buf_utc);
841 /* Open the local database which tracks all objects that are stored
842 * remotely, for efficient incrementals. Provide it with the name of this
844 string database_path = localdb_dir + "/localdb.sqlite";
846 db->Open(database_path.c_str(), desc_buf, backup_scheme.c_str(),
849 tss = new TarSegmentStore(remote, db);
851 /* Initialize the stat cache, for skipping over unchanged files. */
852 metawriter = new MetadataWriter(tss, localdb_dir.c_str(), desc_buf,
853 backup_scheme.c_str());
855 for (int i = optind; i < argc; i++) {
859 ObjectReference root_ref = metawriter->close();
860 add_segment(root_ref.get_segment());
861 string backup_root = root_ref.to_string();
869 /* Write out a checksums file which lists the checksums for all the
870 * segments included in this snapshot. The format is designed so that it
871 * may be easily verified using the sha1sums command. */
872 const char csum_type[] = "sha1";
873 string checksum_filename = "snapshot-";
874 if (backup_scheme.size() > 0)
875 checksum_filename += backup_scheme + "-";
876 checksum_filename = checksum_filename + desc_buf + "." + csum_type + "sums";
877 RemoteFile *checksum_file = remote->alloc_file(checksum_filename,
879 FILE *checksums = fdopen(checksum_file->get_fd(), "w");
881 for (std::set<string>::iterator i = segment_list.begin();
882 i != segment_list.end(); ++i) {
883 string seg_path, seg_csum;
884 if (db->GetSegmentChecksum(*i, &seg_path, &seg_csum)) {
885 const char *raw_checksum = NULL;
886 if (strncmp(seg_csum.c_str(), csum_type,
887 strlen(csum_type)) == 0) {
888 raw_checksum = seg_csum.c_str() + strlen(csum_type);
889 if (*raw_checksum == '=')
895 if (raw_checksum != NULL)
896 fprintf(checksums, "%s *%s\n",
897 raw_checksum, seg_path.c_str());
902 SHA1Checksum checksum_csum;
904 checksum_filename = checksum_file->get_local_path();
905 if (checksum_csum.process_file(checksum_filename.c_str())) {
906 csum = checksum_csum.checksum_str();
909 checksum_file->send();
913 /* All other files should be flushed to remote storage before writing the
914 * backup descriptor below, so that it is not possible to have a backup
915 * descriptor written out depending on non-existent (not yet written)
919 /* Write a backup descriptor file, which says which segments are needed and
920 * where to start to restore this snapshot. The filename is based on the
921 * current time. If a signature filter program was specified, filter the
922 * data through that to give a chance to sign the descriptor contents. */
923 string desc_filename = "snapshot-";
924 if (backup_scheme.size() > 0)
925 desc_filename += backup_scheme + "-";
926 desc_filename = desc_filename + desc_buf + ".lbs";
928 RemoteFile *descriptor_file = remote->alloc_file(desc_filename,
930 int descriptor_fd = descriptor_file->get_fd();
931 if (descriptor_fd < 0) {
932 fprintf(stderr, "Unable to open descriptor output file: %m\n");
935 pid_t signature_pid = 0;
936 if (signature_filter.size() > 0) {
937 int new_fd = spawn_filter(descriptor_fd, signature_filter.c_str(),
939 close(descriptor_fd);
940 descriptor_fd = new_fd;
942 FILE *descriptor = fdopen(descriptor_fd, "w");
944 fprintf(descriptor, "Format: Cumulus Snapshot v0.11\n");
945 fprintf(descriptor, "Producer: Cumulus %s\n", cumulus_version);
946 strftime(desc_buf, sizeof(desc_buf), "%Y-%m-%d %H:%M:%S %z",
948 fprintf(descriptor, "Date: %s\n", desc_buf);
949 if (backup_scheme.size() > 0)
950 fprintf(descriptor, "Scheme: %s\n", backup_scheme.c_str());
951 fprintf(descriptor, "Backup-Intent: %g\n", snapshot_intent);
952 fprintf(descriptor, "Root: %s\n", backup_root.c_str());
954 if (csum.size() > 0) {
955 fprintf(descriptor, "Checksums: %s\n", csum.c_str());
958 fprintf(descriptor, "Segments:\n");
959 for (std::set<string>::iterator i = segment_list.begin();
960 i != segment_list.end(); ++i) {
961 fprintf(descriptor, " %s\n", i->c_str());
968 waitpid(signature_pid, &status, 0);
970 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
971 fatal("Signature filter process error");
975 descriptor_file->send();
980 if (backup_script != "") {
981 if (rmdir(tmp_dir.c_str()) < 0) {
983 "Warning: Cannot delete temporary directory %s: %m\n",