From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B6F59431FBF for ; Tue, 1 Apr 2014 20:35:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 cWBBwKR9oUPu for ; Tue, 1 Apr 2014 20:35:46 -0700 (PDT) Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu [18.7.68.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 05F9C431FBD for ; Tue, 1 Apr 2014 20:35:45 -0700 (PDT) X-AuditID: 12074423-f79476d000000c51-1e-533b85901910 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id BC.0E.03153.0958B335; Tue, 1 Apr 2014 23:35:44 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s323Zil7021060; Tue, 1 Apr 2014 23:35:44 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s323Zgo1010340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Tue, 1 Apr 2014 23:35:43 -0400 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80) (envelope-from ) id 1WVBxm-0004d3-BF; Tue, 01 Apr 2014 23:35:42 -0400 Date: Tue, 1 Apr 2014 23:35:42 -0400 From: Austin Clements To: David Bremner Subject: Re: [Patch v5 5/6] notmuch-new: backup tags before database upgrade Message-ID: <20140402033542.GC25677@mit.edu> References: <1396401381-18128-1-git-send-email-david@tethera.net> <1396401381-18128-6-git-send-email-david@tethera.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1396401381-18128-6-git-send-email-david@tethera.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpileLIzCtJLcpLzFFi42IR4hTV1p3Qah1ssG2bicWN1m5Gi+s3ZzI7 MHk8W3WL2WPLoffMAUxRXDYpqTmZZalF+nYJXBl/W++xFRyUrFj5eCVzA+NH4S5GTg4JAROJ m8/+M0LYYhIX7q1n62Lk4hASmM0ksX7KBSYIZwOjxIK29+wQzikmieurNkCVLWGUePz8I2sX IwcHi4CKxMMJKiCj2AQ0JLbtXw42VkRAVeLqtslsIDazgLTEt9/NTCC2sICPxNl/FxhBWnkF dCRW/VYDCQsJVEp83XSAGcTmFRCUODnzCQtEq5bEjX8vmUDKQcYs/8cBEuYUcJLoOzgFbJMo 0AFTTm5jm8AoNAtJ9ywk3bMQuhcwMq9ilE3JrdLNTczMKU5N1i1OTszLSy3SNdPLzSzRS00p 3cQICmp2F+UdjH8OKh1iFOBgVOLhlbhkFSzEmlhWXJl7iFGSg0lJlJcj2DpYiC8pP6UyI7E4 I76oNCe1+BCjBAezkgjvd1+gHG9KYmVValE+TEqag0VJnPetNdAkgfTEktTs1NSC1CKYrAwH h5IE74sWoEbBotT01Iq0zJwShDQTByfIcB6g4e9BaniLCxJzizPTIfKnGBWlxHlfgiQEQBIZ pXlwvbCk84pRHOgVYd5/IFU8wIQF1/0KaDAT0GDudVYgg0sSEVJSDYx7pZfszPbJ4OXXXs5b ssEma8l73jlMi/1e6dpGOa6a+vz+Ku3Hv3r/Wb2X+3vEb+932copKx+uvBFaPpv7yK2H0fPf Zv7qSD106c0rOYuOy7f+bvkrntqrn26g8t9XekZDmtAR3yI25XyXRS6+WTv2vjBLqkhSD1wt r8K8qp/prMmd/IfX01OVWIozEg21mIuKEwGUO3diFQMAAA== Cc: notmuch@notmuchmail.org 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: Wed, 02 Apr 2014 03:35:50 -0000 Quoth David Bremner on Apr 01 at 10:16 pm: > 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..e0431c6 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/backup-%04d-%02d-%02d-%02d:%02d:%02d.gz", Maybe "dump" instead of "backup" so it's more obvious that it's a notmuch dump? This would be ISO 8601 compatible if you put a 'T' instead of a '-' between the date and the time. Colons tend to get file names into trouble (some file systems don't support them, tools like scp think they demarcate host names, etc). How about compact ISO 8601: 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); Add "..." to indicate a running process? Even better would be a progress report, but we can add that to TODO. > + } > + > + if (notmuch_database_dump (notmuch, backup_name, "", > + DUMP_FORMAT_BATCH_TAG, TRUE)) { > + fprintf (stderr, "Backup failed. Aborting upgrade"); Add a "." at the end for consistency. > + 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." >