]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch-new: backup tags before database upgrade
authorDavid Bremner <david@tethera.net>
Tue, 1 Apr 2014 14:06:05 +0000 (11:06 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 12 Apr 2014 10:59:44 +0000 (07:59 -0300)
All we do here is calculate the backup filename, and call the existing
dump routine.

Also take the opportunity to add a message about being safe to
interrupt.

notmuch-new.c
test/T530-upgrade.sh

index 82acf695353e614e97c1afc91a079f54d20a95f9..d269c7cd7e254badd4ae85ca026a478a8cad4655 100644 (file)
@@ -989,8 +989,35 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])
            return EXIT_FAILURE;
 
        if (notmuch_database_needs_upgrade (notmuch)) {
            return EXIT_FAILURE;
 
        if (notmuch_database_needs_upgrade (notmuch)) {
-           if (add_files_state.verbosity >= VERBOSITY_NORMAL)
+           time_t now = time (NULL);
+           struct tm *gm_time = gmtime (&now);
+
+           /* since dump files are written atomically, the amount of
+            * harm from overwriting one within a second seems
+            * relatively small. */
+
+           const char *backup_name =
+               talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz",
+                                dot_notmuch_path,
+                                gm_time->tm_year + 1900,
+                                gm_time->tm_mon + 1,
+                                gm_time->tm_mday,
+                                gm_time->tm_hour,
+                                gm_time->tm_min,
+                                gm_time->tm_sec);
+
+           if (add_files_state.verbosity >= VERBOSITY_NORMAL) {
                printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");
                printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");
+               printf ("This process is safe to interrupt.\n");
+               printf ("Backing up tags to %s...\n", backup_name);
+           }
+
+           if (notmuch_database_dump (notmuch, backup_name, "",
+                                      DUMP_FORMAT_BATCH_TAG, TRUE)) {
+               fprintf (stderr, "Backup failed. Aborting upgrade.");
+               return EXIT_FAILURE;
+           }
+
            gettimeofday (&add_files_state.tv_start, NULL);
            notmuch_database_upgrade (notmuch,
                                      add_files_state.verbosity >= VERBOSITY_NORMAL ? upgrade_print_progress : NULL,
            gettimeofday (&add_files_state.tv_start, NULL);
            notmuch_database_upgrade (notmuch,
                                      add_files_state.verbosity >= VERBOSITY_NORMAL ? upgrade_print_progress : NULL,
index 67bbf319a1b7b271212fa6e0d7b74794d293ac07..d46e3d1703e1f597b835b2d85be154240dbe235d 100755 (executable)
@@ -26,9 +26,11 @@ output=$(notmuch search path:foo)
 test_expect_equal "$output" ""
 
 test_begin_subtest "database upgrade from format version 1"
 test_expect_equal "$output" ""
 
 test_begin_subtest "database upgrade from format version 1"
-output=$(notmuch new)
+output=$(notmuch new | sed -e 's/^Backing up tags to .*$/Backing up tags to FILENAME/')
 test_expect_equal "$output" "\
 Welcome to a new version of notmuch! Your database will now be upgraded.
 test_expect_equal "$output" "\
 Welcome to a new version of notmuch! Your database will now be upgraded.
+This process is safe to interrupt.
+Backing up tags to FILENAME
 Your notmuch database has now been upgraded to database format version 2.
 No new mail."
 
 Your notmuch database has now been upgraded to database format version 2.
 No new mail."