Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0FADA431FC7 for ; Thu, 3 Apr 2014 19:44:41 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nhOasN8K3G97 for ; Thu, 3 Apr 2014 19:44:37 -0700 (PDT) Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net [87.98.215.224]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id B0128431FBF for ; Thu, 3 Apr 2014 19:44:32 -0700 (PDT) Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim 4.72) (envelope-from ) id 1WVtXU-00017G-Nl; Fri, 04 Apr 2014 02:07:28 +0000 Received: (nullmailer pid 4020 invoked by uid 1000); Thu, 03 Apr 2014 19:41:39 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [Patch v6 5/6] notmuch-new: backup tags before database upgrade Date: Thu, 3 Apr 2014 16:41:22 -0300 Message-Id: <1396554083-3892-6-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1396554083-3892-1-git-send-email-david@tethera.net> References: <1396554083-3892-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Apr 2014 02:44:41 -0000 All we do here is calculate the backup filename, and call the existing dump routine. Also take the opportity to add a message about being safe to interrupt. --- notmuch-new.c | 29 ++++++++++++++++++++++++++++- test/T530-upgrade.sh | 4 +++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 82acf69..d269c7c 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -989,8 +989,35 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) 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 ("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, diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh index 67bbf31..d46e3d1 100755 --- a/test/T530-upgrade.sh +++ b/test/T530-upgrade.sh @@ -26,9 +26,11 @@ output=$(notmuch search path:foo) 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. +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." -- 1.9.0