You are here: Home / Documentation / How To's / How to export and import Plone users

How to export and import Plone users

by nguyen — published Oct 04, 2014 07:50 PM, last modified Aug 16, 2016 10:50 AM
using bin/instance debug

I found this very useful information which shows how to copy the usernames and passwords from one Plone site to another, by exporting the credentials into a file then reading the file into another site:

import cPickle

def export(self):
    pas = self.acl_users
    users = pas.source_users
    passwords = users._user_passwords
    result = dict(passwords)

    f = open('/tmp/out.blob', 'w')
    cPickle.dump(result, f)

    return "done"

def import_users(self):
    pas = self.acl_users
    users = pas.source_users
    f = open('/tmp/out.blob')
    res = cPickle.load(f)

    for uid, pwd in res.items():
        users.addUser(uid, uid, pwd)

    return "done"

However, I didn't want to use a file since I have a small number of users to copy. Instead, I used the ZEO client in "debug" mode to copy the username & password dictionary.


Getting the credentials from the source site

On the source site I did started the instance in debug mode (you could do this with a ZEO client too if you have a ZEO setup by using bin/client1 for example):

$ bin/instance debug

>>> mysite=app.MYSITEID

>>> pas=mysite.acl_users

>>> users=pas.source_users

>>> passwords=users._user_passwords

>>> dict(passwords)

{'user1': '{SSHA}hashedpw1', 'user2': '{SSHA}hashpw2'}

I copied the last line (the passwords dictionary contents) to my terminal clipboard.

Applying the credentials on the destination site

Then on the destination site I launched the instance in debug mode and navigated back down to the same spot.  

Then I defined a variable called "passwords" and set it to the text I'd copied into my clipboard above. That's the line that starts with "passwords =".

Then, using that new "passwords" variable, I made a for loop and called the users.addUser() method with each set of credentials in the passwords dictionary.

Finally I committed the ZODB transaction to make the new users persist in the database.

$ bin/instance debug

>>> newsite=app.NEWSITEID

>>> pas=newsite.acl_users

>>> users=pas.source_users

>>> passwords = dict({'user1': '{SSHA}hashedpw1', 'user2': '{SSHA}hashpw2'})

>>> for u in passwords:

...   users.addUser(u, u, passwords[u])


>>> import transaction

>>> transaction.commit()



See Also

This documentation explains "Exporting and importing member passwords":