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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file mongo-operator-0.0.4.tar.gz.

File metadata

  • Download URL: mongo-operator-0.0.4.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for mongo-operator-0.0.4.tar.gz
Algorithm Hash digest
SHA256 78fcdc2c6e6b177770ab2b143f460896c08be92c510ab5fd673c22db2a4eea34
MD5 9fff846e9a2edfc4a43a73fbdf80ab72
BLAKE2b-256 549c99131945b87b2e3cee3a1e0a656ef268287b12a42a22eaadb37cc47bd966

See more details on using hashes here.

File details

Details for the file mongo_operator-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: mongo_operator-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.5

File hashes

Hashes for mongo_operator-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5d0ab25748ea1229c4ac9031990f614dd12477b57e7326a1e5be38a5130ee769
MD5 43d0f95e1173e20240b0cb8fb2d76ca2
BLAKE2b-256 9f47c9ab4093b5e1bab1154faebd0cd38c8596f83fef121154287f9c7e487d39

See more details on using hashes here.

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