[PATCH v3] Re: True 1-way sync (backup)

Nicolas Sebrecht nicolas.s-dev at laposte.net
Thu Mar 31 17:55:38 BST 2011


[ Is this y at lapostedotnet correct? ]

On Thu, Mar 31, 2011 at 09:23:41AM -0400, y at laposte.net wrote:
> 
> From: Sebastian Spaeth <Sebastian at SSpaeth.de>
> 
> This commit enables true 1-way syncing between repositories. This has
> often been demanded for backup purposes when you do not want to cause
> accidental modifications of your backup to mess up the main IMAP
> server.
> 
> This has been implemented by allowing to configure a Repository as
> 'readonly'. This repository will then not be modified during the sync.
> 
> For most use cases users will want to set the remote repository to
> read-only (so that added folders still show up in the "local" backup),
> although the local repository could be set readonly too. (If both are set
> read-only, the sync will not modify anything).
> 
> 'readonly' applies to any type of repository (IMAP, Gmail, Maildir,
> UIDMapped).

Ok, what about:

  This commit enables true 1-way syncing between repositories. This has
  often been demanded for backup purposes when you do not want to cause
  accidental modifications of your backup that would be propegated to
  the other side.
  
  This has been implemented by allowing to configure a Repository as
  'readonly' to forbid any modification on it.
  
  'readonly' applies to all the type of repositories.

> Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
> ---
> Hopefully address Nicolas' concerns by improving the descriptions. I
> will send an interpatch.diff to explain the differences.

Thanks for that. A basic 'git diff feature-v0 feature-v1' would be much
easier to read, though.

>                                                          Also clarified
> the ignore-readonly setting description to explain that it's unrelated
> to readonly.

Good.

> diff --git a/Changelog.draft.rst b/Changelog.draft.rst
> index 79006fd..8dcbc89 100644
> --- a/Changelog.draft.rst
> +++ b/Changelog.draft.rst
> @@ -13,6 +13,11 @@ others.
>  New Features
>  ------------
>  
> +* Enable 1-way synchronization by settting a [Repository ...] to
> +  readonly = True. When e.g. using offlineimap for backup purposes you
> +  can thus make sure that no changes in your backup trickle back into
> +  the main IMAP server.
> +
>  Changes
>  -------
>  
> diff --git a/offlineimap.conf b/offlineimap.conf
> index c0ff8d7..2a8ff6e 100644
> --- a/offlineimap.conf
> +++ b/offlineimap.conf
> @@ -1,6 +1,5 @@
>  # Sample configuration file
> -# Copyright (C) 2002-2005 John Goerzen
> -# <jgoerzen at complete.org>
> +# Copyright (C) 2002-2011 John Goerzen & contributors
>  #
>  #    This program is free software; you can redistribute it and/or modify
>  #    it under the terms of the GNU General Public License as published by
> @@ -67,13 +66,14 @@ maxsyncaccounts = 1
>  
>  ui = Blinkenlights
>  
> -# If you try to synchronize messages to a read-only folder,
> -# OfflineIMAP will generate a warning.  If you want to suppress these
> -# warnings, set ignore-readonly to yes.  Read-only IMAP folders allow
> -# reading but not modification, so if you try to change messages in
> -# the local copy of such a folder, the IMAP server will prevent
> -# OfflineIMAP from propagating those changes to the IMAP server.
> -
> +# If you try to synchronize messages to a folder which the IMAP server
> +# considers read-only, OfflineIMAP will generate a warning.

We lost an important description, here. What OfflineIMAP will /consider/
read-only? Is it related to usual unix rights on the folder, on the
repository or what?

In short, we can't remove the "read-only IMAP folder allow" part.

> +#                                                            If you want
> +# to suppress these warnings, set ignore-readonly to yes.  Read-only
> +# IMAP folders allow reading but not modification, so if you try to
> +# change messages in the local copy of such a folder, the IMAP server
> +# will prevent OfflineIMAP from propagating those changes to the IMAP
> +# server.  Note that ignore-readonly is unrelated to the "readonly"
> +# setting which prevents a repository from being modified at all.
>  ignore-readonly = no
>  
>  ########## Advanced settings
> @@ -458,6 +458,11 @@ subscribedonly = no
>  #
>  # foldersort = lambda x, y: -cmp(x, y)
>  
> +# Enable 1-way synchronization. When setting 'readonly' to True, this
> +# repository will not be modified during synchronization. Use to
> +# e.g. backup an IMAP server. The readonly setting can be applied to any
> +# type of Repository (Maildir, Imap, etc).
> +readonly = False
>  
>  [Repository GmailExample]
>  
> @@ -498,3 +503,5 @@ realdelete = no
>  #
>  # spamfolder = [Google Mail]/Spam
>  
> +# Enable 1-way synchronization. See above for explanation.
> +readonly = False
> diff --git a/offlineimap/accounts.py b/offlineimap/accounts.py
> index 7edfa37..e39a72e 100644
> --- a/offlineimap/accounts.py
> +++ b/offlineimap/accounts.py
> @@ -242,8 +242,10 @@ class SyncableAccount(Account):
>              remoterepos = self.remoterepos
>              localrepos = self.localrepos
>              statusrepos = self.statusrepos
> -            self.ui.syncfolders(remoterepos, localrepos)
> -            remoterepos.syncfoldersto(localrepos, [statusrepos])
> +            # replicate the folderstructure from REMOTE to LOCAL
> +            if not localrepos.getconf('readonly', False):
> +                self.ui.syncfolders(remoterepos, localrepos)
> +                remoterepos.syncfoldersto(localrepos, [statusrepos])
>  
>              siglistener.addfolders(remoterepos.getfolders(), bool(self.refreshperiod), quick)
>  
> @@ -349,12 +351,20 @@ def syncfolder(accountname, remoterepos, remotefolder, localrepos,
>                               remotefolder.getmessagecount())
>  
>          # Synchronize remote changes.
> -        ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
> -        remotefolder.syncmessagesto(localfolder, statusfolder)
> +        if not localrepos.getconf('readonly', False):
> +            ui.syncingmessages(remoterepos, remotefolder, localrepos, localfolder)
> +            remotefolder.syncmessagesto(localfolder, statusfolder)
> +        else:
> +            ui.debug('imap',"Not syncing to read-only repository '%s'" \
                               ^
                               would be better with a whitespace

Sorry to not have caught it before.

> +                         % localrepos.getname())
> +        
>          # Synchronize local changes
> -        ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
> -        localfolder.syncmessagesto(remotefolder, statusfolder)
> -
> +        if not remoterepos.getconf('readonly', False):
> +            ui.syncingmessages(localrepos, localfolder, remoterepos, remotefolder)
> +            localfolder.syncmessagesto(remotefolder, statusfolder)
> +        else:
> +            ui.debug('imap',"Not syncing to read-only repository '%s'" \
                               ^
                               ditto
> +                         % remoterepos.getname())

This 'imap' type still looks wrong to me. I'm really expecting to
introduce another new type '' or 'None' to ignore it before introducing
this patch.

-- 
Nicolas Sebrecht




More information about the OfflineIMAP-project mailing list