Google App API - Migrate all users's emails from old domain to the new one

I'm using the following procedure to migrate all users's emails from old google domain to the new one:


1. Enable IMAP on all user accounts in the old domain. Use the enable_imap.py script from my previous blog post:

http://iambusychangingtheworld.blogspot.com/2013/12/google-email-settings-api-enable-imap.html

2. Loop through each user and executing these following steps:

a. Run the gyb.py script to backup emails from old domain account:

def backup_emails(email, service_account_email, email_folder):
    command = [
        "python", "gyb.py",
        "--email", email,
        "--action", "backup",
        "--local-folder", email_folder,
        "--service-account", service_account_email
    ]
    print "Executing commnad: %s" % command
    subprocess.call(command)


b. Run gyb.py script to restore backup-ed emails to new domain account:

def restore_emails(email, service_account_email, email_folder):
    command = [
        "python", "gyb.py",
        "--email", email,
        "--action", "restore",
        "--local-folder", email_folder,
        "--service-account", service_account_email
    ]
    print "Executing commnad: %s" % command
    subprocess.call(command)


c. Remove emails folder, reserve space for next user:

def erase_backuped_emails(email_folder):
    email_folder += '/*'
    command = 'rm -rf %s' % email_folder
    print "Executing commnad: %s" % command
    subprocess.call(command, shell=True)




You can check the project at Github repository: https://github.com/dangtrinh/gem

Comments