Results 1 to 2 of 2

Thread: Need Help Merging Duplicated Archive accounts

  1. #1
    Join Date
    Feb 2010
    Posts
    12
    Rep Power
    5

    Default SOLVED: Need Help Merging Duplicated Archive accounts

    We're currently running Zimbra NE 6.0.10 in a multi-server environment, and we encountered a problem (with an account import script) where archive accounts were duplicated.

    Each account now has two zimbraArchiveAccount attributes, and thus two archive mailboxes. We need to consolidate or merge the archive mailboxes for each regular mailbox, and I'm looking for advice on the best way to approach this.

    At the moment, I'm thinking of writing a script to enumerate all/each account, determine the zimbraArchiveAccount attribute values, remove the duplicate, merge/sync the archive mailboxes, and then delete the duplicate archive maibox. Sounds like imapsync is the tool to use here for syncing.

    Has anyone else accomplished something similar? Any advice?

    Regards,
    Mike
    Last edited by nwcon; 07-11-2012 at 05:13 PM.

  2. #2
    Join Date
    Feb 2010
    Posts
    12
    Rep Power
    5

    Default SOLVED: Need Help Merging Duplicated Archive accounts

    Thought I'd share the solution. I hacked a quick script and completed the task. Here's my script:

    zimbra-fix-dup-arch-mailboxes.py



    #!/usr/bin/env python
    #

    import os, sys, commands



    acctsfile='allaccounts'
    dupattr='20120710'



    f = open(acctsfile, 'r')
    accts = f.readlines()
    f.close()

    l = open('fix-dups.log', 'a')


    for acct in accts:
    if acct.endswith('\n') or acct.endswith('\r'):
    acct = acct[:-1]
    elif acct.endswith('\r\n'):
    acct = acct[:-2]

    username,domain = acct.split('@')
    attrs=commands.getstatusoutput("zmprov ga " + acct + " zimbraArchiveAccount | grep zimbraArchiveAccount | sed 's/\ //g'")[1]
    attrs = attrs.split('\n')

    # cleanup
    attrs_tmp = []
    if len(attrs) > 0:
    for a in attrs:
    if a == '':
    attrs_tmp.append('')
    else:
    t = a.split(':')[1]
    attrs_tmp.append(t)

    attrs = attrs_tmp
    attrs_tmp = []

    count=len(attrs)
    # first get account attribute zimbraArchiveAccount attr. Check
    # if the count is 0, 1 or 2. There _shouldn't_ be any accounts with more
    # than 2. If so, we'll just print the acct and the count, so we can
    # handle them separately.
    #
    # If
    #
    # 1. count is 0, skip account.
    # 2. count is 1, ensure zimbraArchiveAccount and amavisArchiveQuarantineTo
    # have the same value.
    # 3. count is more than 1, delete dup attr, set amavisArchiveQuarantineTo
    # to correct mailbox value, sync dup archive mailbox to correct archive
    # mailbox, and then delete dup archive mailbox.
    #

    if count == 0:
    l.writelines(acct + ": doesn't have archiving enabled.\n")
    l.flush()

    elif count == 1:
    l.writelines(acct + ": has only one archive attr.\n")
    l.flush()
    #attrval=$(zmprov ga $acct zimbraArchiveAccount | grep zimbraArchiveAccount | awk -F ': ' '{ print $2}')
    #zmprov ma $acct amavisArchiveQuarantineTo $attrval
    #print "done."

    elif count == 2:
    if attrs[0].find(dupattr) <> -1:
    dupattrval=attrs[0]
    correctval=attrs[1]
    elif attrs[1].find(dupattr) <> -1:
    dupattrval=attrs[1]
    correctval=attrs[0]
    else:
    l.writelines(acct + ": has duplicate archives, but neither match 20120710!\n")
    l.flush()
    dupattrval=''
    correctval=''


    if len(dupattrval) > 0 and len(correctval) > 0:
    l.writelines(acct + ": fixing duplicate archives...")
    l.flush()

    # remove dup attr
    r = commands.getstatusoutput('zmprov ma ' + acct + ' -zimbraArchiveAccount ' + dupattrval )[1]
    #print r
    # update amavisArchiveQuarantineTo
    r = commands.getstatusoutput('zmprov ma ' + acct + ' amavisArchiveQuarantineTo ' + correctval)[1]
    #print r
    # export dup arch mb
    r = commands.getstatusoutput('zmmailbox -z -m ' + dupattrval + ' getRestURL "//?fmt=tgz" > /tmp/'+username+'.tgz')[1]
    r = commands.getstatusoutput('zmmailbox -z -m ' + dupattrval + ' getRestURL "//junk?fmt=tgz" > /tmp/'+username+'-junk.tgz')[1]
    #print r
    # import into correct arch mb
    r = commands.getstatusoutput('zmmailbox -z -m ' + correctval + ' postRestURL "//?fmt=tgz" /tmp/'+username+'.tgz')[1]
    r = commands.getstatusoutput('zmmailbox -z -m ' + correctval + ' postRestURL "//?fmt=tgz" /tmp/'+username+'-junk.tgz')[1]
    #print r
    # delete export file
    os.remove('/tmp/'+username+'.tgz')
    os.remove('/tmp/'+username+'-junk.tgz')
    # remove archive mb
    r = commands.getstatusoutput('zmprov da ' + dupattrval)[1]
    #print r

    l.writelines('done.\n')
    l.flush()

    else:
    l.writelines(acct + ": has more than 2 archive attrs\n")
    l.flush()



    l.close()

Similar Threads

  1. Delete old archive accounts?
    By fnbwaseca in forum Administrators
    Replies: 0
    Last Post: 11-29-2010, 09:17 AM
  2. Bulk Create for Archive Accounts
    By cswihart in forum Administrators
    Replies: 3
    Last Post: 09-26-2008, 03:04 PM
  3. Error Adding new archive accounts
    By peter@mxtoolbox.com in forum Administrators
    Replies: 2
    Last Post: 03-11-2008, 08:35 AM
  4. Merging of email accounts
    By martinyao in forum Administrators
    Replies: 1
    Last Post: 01-06-2008, 11:18 PM
  5. Adding existing accounts to archive
    By chh in forum Administrators
    Replies: 4
    Last Post: 09-06-2007, 01:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •