Add a flag to force a full rewrite of the metadata log in a snapshot.
[cumulus.git] / scandir.cc
index 654f9fb..7a7ba46 100644 (file)
@@ -57,6 +57,11 @@ LocalDb *db;
 /* Keep track of all segments which are needed to reconstruct the snapshot. */
 std::set<string> segment_list;
 
+/* Snapshot intent: 1=daily, 7=weekly, etc.  This is not used directly, but is
+ * stored in the local database and can help guide segment cleaning and
+ * snapshot expiration policies. */
+double snapshot_intent = 1.0;
+
 /* Selection of files to include/exclude in the snapshot. */
 std::list<string> includes;         // Paths in which files should be saved
 std::list<string> excludes;         // Paths which will not be saved
@@ -138,7 +143,7 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
                 const ObjectReference &ref = *i;
                 object_list.push_back(ref.to_string());
                 if (ref.is_normal())
-                    segment_list.insert(ref.get_segment());
+                    add_segment(ref.get_segment());
                 db->UseObject(ref);
             }
             size = stat_buf.st_size;
@@ -184,7 +189,7 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
                 ref = ObjectReference(ObjectReference::REF_ZERO);
                 ref.set_range(0, bytes);
             } else {
-                ObjectReference ref = db->FindObject(block_csum, bytes);
+                ref = db->FindObject(block_csum, bytes);
             }
 
             // Store a copy of the object if one does not yet exist
@@ -223,12 +228,13 @@ int64_t dumpfile(int fd, dictionary &file_info, const string &path,
                 o->write(tss);
                 ref = o->get_ref();
                 db->StoreObject(ref, block_csum, bytes, block_age);
+                ref.set_range(0, bytes);
                 delete o;
             }
 
             object_list.push_back(ref.to_string());
             if (ref.is_normal())
-                segment_list.insert(ref.get_segment());
+                add_segment(ref.get_segment());
             db->UseObject(ref);
             size += bytes;
 
@@ -557,7 +563,10 @@ void usage(const char *program)
         "                           (defaults to \".bz2\")\n"
         "  --signature-filter=COMMAND\n"
         "                       program though which to filter descriptor\n"
-        "  --scheme=NAME        optional name for this snapshot\n",
+        "  --scheme=NAME        optional name for this snapshot\n"
+        "  --intent=FLOAT       intended backup type: 1=daily, 7=weekly, ...\n"
+        "                           (defaults to \"1\")\n"
+        "  --full-metadata      do not re-use metadata from previous backups\n",
         lbs_version, program
     );
 }
@@ -578,6 +587,8 @@ int main(int argc, char *argv[])
             {"dest", 1, 0, 0},              // 4
             {"scheme", 1, 0, 0},            // 5
             {"signature-filter", 1, 0, 0},  // 6
+            {"intent", 1, 0, 0},            // 7
+            {"full-metadata", 0, 0, 0},     // 8
             {NULL, 0, 0, 0},
         };
 
@@ -613,6 +624,14 @@ int main(int argc, char *argv[])
             case 6:     // --signature-filter
                 signature_filter = optarg;
                 break;
+            case 7:     // --intent
+                snapshot_intent = atof(optarg);
+                if (snapshot_intent <= 0)
+                    snapshot_intent = 1;
+                break;
+            case 8:     // --full-metadata
+                flag_full_metadata = true;
+                break;
             default:
                 fprintf(stderr, "Unhandled long option!\n");
                 return 1;
@@ -683,7 +702,8 @@ int main(int argc, char *argv[])
     string database_path = localdb_dir + "/localdb.sqlite";
     db = new LocalDb;
     db->Open(database_path.c_str(), desc_buf,
-             backup_scheme.size() ? backup_scheme.c_str() : NULL);
+             backup_scheme.size() ? backup_scheme.c_str() : NULL,
+             snapshot_intent);
 
     tss = new TarSegmentStore(backup_dest, db);