Skip to main content

A tool for backup/cleanup/migrate mongo

Project description

mongo-operator

A package for backup / cleanup / migrate mongodb.

Description:

A tool for backup / cleanup / migrate mongo.

This package can make you backup / cleanup / migrate more earlier with python3.

Initial testing data

  1. download https://github.com/chienfeng0719/mongo-operator/tree/develop/mongo_init
  2. run command mongo-operator -r mongo_init

How To Use:

You can use mongo-operator through command line for backup/restore/drop database as the following example:

CLI

mongo-operator -b foo_bar -> backup foo_bar
mongo-operator -d foo_bar -> drop foo_bar
mongo-operator -r mongo_init -> restore data from mongo_init folder

You can also do some advanced operate with python:

Backup

from mongo_operator import BackupOperator

# init object
backup_operator = BackupOperator(hostname='localhost', port=27017, username='root', password='root')

# backup all database
backup_operator.backup(folder_path='./backup/')

# backup specific collection
backup_operator.backup(db_name='foo_bar', collection='foo_bar')

# backup specific collection with query
backup_operator.backup(db_name='foo_bar', collection='foo_bar', query_={'items': 'phone'})

# restore data from backup
backup_operator.restore(folder_path='./backup/', is_dropped=True)

Cleanup

from mongo_operator import CleanupOperator

# init object
cleanup_operator = CleanupOperator(hostname='localhost', port=27017, username='root', password='root')

# drop 'foo_bar' table in foo_bar
cleanup_operator.drop_collection(db_name='foo_bar', collection='foo_bar')

# drop foo_bar database
cleanup_operator.drop_db(db_name='foo_bar')

Migrate

from mongo_operator import MigrateOperator

# init object
migrate_operator = MigrateOperator(hostname='localhost',
                                   port=27017,
                                   username='root',
                                   password='root',
                                   target_hostname='192.168.1.1',
                                   target_port=27017,
                                   target_username='root',
                                   target_password='root')

# import all database from target host
migrate_operator.import_database()

# import『foo_bar』database from target host
migrate_operator.import_database(db_name='foo_bar')

# export all database from to host
migrate_operator.export_database()

# export『foo_bar』database to target host
migrate_operator.export_database(db_name='foo_bar')

Buy Me A Coffee

Buy me a coffee, if you like it!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongo-operator-0.0.4.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

mongo_operator-0.0.4-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page