[Patch v7 5/6] notmuch-new: backup tags before database upgrade
authorDavid Bremner <david@tethera.net>
Sat, 5 Apr 2014 15:43:55 +0000 (12:43 +2100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:01:13 +0000 (10:01 -0800)
f4/4c1ddd730584beb961567ff0ed48fabc2a7d93 [new file with mode: 0644]

diff --git a/f4/4c1ddd730584beb961567ff0ed48fabc2a7d93 b/f4/4c1ddd730584beb961567ff0ed48fabc2a7d93
new file mode 100644 (file)
index 0000000..9994422
--- /dev/null
@@ -0,0 +1,119 @@
+Return-Path: <bremner@tesseract.cs.unb.ca>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 25535431FC9\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Apr 2014 08:46:05 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ZeZXqlqxkebw for <notmuch@notmuchmail.org>;\r
+       Sat,  5 Apr 2014 08:46:01 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+       [87.98.215.224]) (using TLSv1 with cipher AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id D4A4D431FB6\r
+       for <notmuch@notmuchmail.org>; Sat,  5 Apr 2014 08:45:56 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+       4.72) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+       id 1WWSmR-00082k-MC; Sat, 05 Apr 2014 15:45:15 +0000\r
+Received: (nullmailer pid 10920 invoked by uid 1000); Sat, 05 Apr 2014\r
+       15:43:59 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v7 5/6] notmuch-new: backup tags before database upgrade\r
+Date: Sat,  5 Apr 2014 12:43:55 -0300\r
+Message-Id: <1396712636-10640-6-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 1.9.0\r
+In-Reply-To: <1396712636-10640-1-git-send-email-david@tethera.net>\r
+References: <1396712636-10640-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 05 Apr 2014 15:46:05 -0000\r
+\r
+All we do here is calculate the backup filename, and call the existing\r
+dump routine.\r
+\r
+Also take the opportity to add a message about being safe to\r
+interrupt.\r
+---\r
+ notmuch-new.c        | 29 ++++++++++++++++++++++++++++-\r
+ test/T530-upgrade.sh |  4 +++-\r
+ 2 files changed, 31 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 82acf69..d269c7c 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -989,8 +989,35 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+           return EXIT_FAILURE;\r
\r
+       if (notmuch_database_needs_upgrade (notmuch)) {\r
+-          if (add_files_state.verbosity >= VERBOSITY_NORMAL)\r
++          time_t now = time (NULL);\r
++          struct tm *gm_time = gmtime (&now);\r
++\r
++          /* since dump files are written atomically, the amount of\r
++           * harm from overwriting one within a second seems\r
++           * relatively small. */\r
++\r
++          const char *backup_name =\r
++              talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz",\r
++                               dot_notmuch_path,\r
++                               gm_time->tm_year + 1900,\r
++                               gm_time->tm_mon + 1,\r
++                               gm_time->tm_mday,\r
++                               gm_time->tm_hour,\r
++                               gm_time->tm_min,\r
++                               gm_time->tm_sec);\r
++\r
++          if (add_files_state.verbosity >= VERBOSITY_NORMAL) {\r
+               printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");\r
++              printf ("This process is safe to interrupt.\n");\r
++              printf ("Backing up tags to %s...\n", backup_name);\r
++          }\r
++\r
++          if (notmuch_database_dump (notmuch, backup_name, "",\r
++                                     DUMP_FORMAT_BATCH_TAG, TRUE)) {\r
++              fprintf (stderr, "Backup failed. Aborting upgrade.");\r
++              return EXIT_FAILURE;\r
++          }\r
++\r
+           gettimeofday (&add_files_state.tv_start, NULL);\r
+           notmuch_database_upgrade (notmuch,\r
+                                     add_files_state.verbosity >= VERBOSITY_NORMAL ? upgrade_print_progress : NULL,\r
+diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh\r
+index 67bbf31..d46e3d1 100755\r
+--- a/test/T530-upgrade.sh\r
++++ b/test/T530-upgrade.sh\r
+@@ -26,9 +26,11 @@ output=$(notmuch search path:foo)\r
+ test_expect_equal "$output" ""\r
\r
+ test_begin_subtest "database upgrade from format version 1"\r
+-output=$(notmuch new)\r
++output=$(notmuch new | sed -e 's/^Backing up tags to .*$/Backing up tags to FILENAME/')\r
+ test_expect_equal "$output" "\\r
+ Welcome to a new version of notmuch! Your database will now be upgraded.\r
++This process is safe to interrupt.\r
++Backing up tags to FILENAME\r
+ Your notmuch database has now been upgraded to database format version 2.\r
+ No new mail."\r
\r
+-- \r
+1.9.0\r
+\r