Giter VIP home page Giter VIP logo

atlas-user-migration's Introduction

Atlas Database User Migration Utility

Atlas provides excellent tools, such as Cluster-to-Cluster Sync, Live Migrate and mongomirror for migrating your data to Atlas. However, neither of these tools import user and role data.

This utility is a Python script that was written to assist migrating your existing database users and roles to Atlas. The only thing it can't migrate is user passwords, so the script randomly generates passwords and saves them to a users.text file.

The script uses the Python driver to fetch your existing users and roles. However, as the createUser command is not supported by Atlas, users need to be created using the Database Users REST api.

To use the tool:

# Input parameters

# Source DB
source_conn_string = <Application connection string>
source_database = 'admin'

# For Atlas REST API
target_project_id = '<Project ID found under Atlas Project Settings>'
target_api_public_key = '<API Public Key>'
target_api_private_key = '<API Private Key>'

Given this existing set of users:

When run the script will display the following:

brianleonard$ python3 migrate_users.py

Migrating MongoDB Users

4 potential users to be migrated

>>> Migrating user:
{'_id': 'admin.brian', 'user': 'brian', 'db': 'admin', 'roles': [{'role': 'readAnyDatabase', 'db': 'admin'}], 'mechanisms': ['SCRAM-SHA-1']}

Formatted roles:
[{'databaseName': 'admin', 'roleName': 'readAnyDatabase'}]

User data sent to Atlas API:
{'databaseName': 'admin', 'roles': [{'databaseName': 'admin', 'roleName': 'readAnyDatabase'}], 'username': 'brian', 'password': 'changeme123'}

User brian created.
>>>

>>> Migrating user:
{'_id': 'admin.david', 'user': 'david', 'db': 'admin', 'roles': [{'role': 'read', 'db': 'marketing'}, {'role': 'readWrite', 'db': 'sales'}], 'mechanisms': ['SCRAM-SHA-1']}

Formatted roles:
[{'databaseName': 'marketing', 'roleName': 'read'}, {'databaseName': 'sales', 'roleName': 'readWrite'}]

User data sent to Atlas API:
{'databaseName': 'admin', 'roles': [{'databaseName': 'marketing', 'roleName': 'read'}, {'databaseName': 'sales', 'roleName': 'readWrite'}], 'username': 'david', 'password': 'changeme123'}

User david created.
>>>

<<<Skipping user mms-automation>>>

>>> Migrating user:
{'_id': 'admin.scott', 'user': 'scott', 'db': 'admin', 'roles': [{'role': 'readWriteAnyDatabase', 'db': 'admin'}], 'mechanisms': ['SCRAM-SHA-1']}

Formatted roles:
[{'databaseName': 'admin', 'roleName': 'readWriteAnyDatabase'}]

User data sent to Atlas API:
{'databaseName': 'admin', 'roles': [{'databaseName': 'admin', 'roleName': 'readWriteAnyDatabase'}], 'username': 'scott', 'password': 'changeme123'}

User scott created.
>>>

And you'll find the users in Atlas:

atlas-user-migration's People

Contributors

wbleonard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.