Partial database migration (users only)

Hello community,

We are planning to move our install (+50 users) to new machines with a better hardware, running under a different dedicated user.

For the new install we want to migrate only the users not the projects.

I can do something like cryosparcm listusers to get a list of current users and I can migrate the whole database, then clean the projects using clear_job or similar. But I was wondering if there is an easier way/recommended way (maybe using mongodb commands and a partial export) since we have more than a hundred projects in our local (+live) install.

What would you recommend?
Any hints about this? Thanks to all!

Best,

Juan

Hi @jucastil,

This can be accomplished in 2 ways:

  1. Install a new cryoSPARC instance under the new user on the new hardware. Use cryosparcm listusers on the old instance to get everyone’s email addresses. Then manually create those same users using the admin interface in the new instance. Each user will need to be sent their register token and they can then set their password in the new instance.
    This is of course a bit manual and cumbersome for 50+ active users.
  1. Install a new cryoSPARC instance under the new user on the new hardware.
    On the old instance, first drop in to the cryosparc shell (cryosparcm icli) then do the following to extract the users collection in the database:
users = list(db.users.find({},{'state':0}))
import pickle
with open('~/cryosparc_users_file.pkl', 'w') as f:
    pickle.dump(users, f)

You should save the cryosparc_users_file.pkl somewhere you can read it easily from the other account.
Then, on the new instance, drop in to the cryosparc shell again, and now do:

with open('~/cryosparc_users_file.pkl') as f:
    users = pickle.load(f)
db.users.insert_many(users)

And now you should have all the old users remade in the new instance, and they will have the same passwords as before.

Please let us know if this works for you.

2 Likes

Yes it worked! Thanks a lot, this will give us a little bit of freedom :slightly_smiling_face:

Hi,

I would like to export and import just one single user from one installation onto another. I am able to use the following command to retrieve relevant info for the user of interest. Please confirm if this is the correct approach, and that I could use the remaining parts of your example commands from above for exporting and importing.

user1 = list(db.users.find({u’name’: u’user1’}))

Thank you.

Harry

Hi @harry,

For a single user, this would be the way to do it:

user1 = db.users.find_one({'name' : 'user1'}, {'state' : 0})
# OR if you know the email address:
user1 = db.users.find_one({'emails.0.address': 'user1@structura.bio'}, {'state' : 0})

import pickle
with open('~/cryosparc_users_file.pkl', 'w') as f:
    pickle.dump(user1, f)

# then, on the other instance
with open('~/cryosparc_users_file.pkl') as f:
    user1 = pickle.load(f)
db.users.insert_one(user1)
2 Likes

@stephan I was able to migrate one single user to another installation with your commands. Thank you.

2 Likes

Hi,

After updating to 3.0.1, the command to export single user info to a file using the “pickle.dump($userinfo,f)” returns TypeError: write() argument must be str not bytes.

Importing 2.15 single user file into 3.01 also has the same type errors. What should the new syntax be?

Thank you.

Hello
With version 4.x, I had to modify the script, here’s what worked for me:

Export users from CryoSPARC instance:

users = list(db.users.find({},{'state':0}))
import pickle
with open('/tmp/cryosparc_users_file.pkl', 'wb') as f:
    pickle.dump(users, f)

Import to new CryoSPARC instance:

import pickle
with open('/tmp/cryosparc_users_file.pkl', 'rb') as f:
    users = pickle.load(f)
db.users.insert_many(users)