py-mongo-backup-restore


Namepy-mongo-backup-restore JSON
Version 2.1.0 PyPI version JSON
download
home_pagehttps://github.com/sannjayy/py-mongo-backup-restore
SummaryPython Library to Backup and Restore MongoDB
upload_time2024-03-10 12:56:26
maintainer
docs_urlNone
authorSanjay Sikdar
requires_python>=3.10, <4
licenseMIT
keywords python mongo backup restore mongodb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Python MongoDB Backup & Restore
Python Library to Backup and Restore MongoDB

GitHub Repo: [https://github.com/sannjayy/py-mongo-backup-restore](https://github.com/sannjayy/py-mongo-backup-restore)
### Installaion
Do the following in your virtualenv:

`pip install py-mongo-backup-restore`

**Import:**
```
from py_mongo_backup_restore import PyMongoBackupRestore
```
---

### Configuration:
```python
from py_mongo_backup_restore import PyMongoBackupRestore

# Database Configuration:
config = {
    'scheme': 'mongodb',
    'host': '37.108.158.64:27017',
    'username': 'username',
    'password': 'password',
    'extra_options': '?authSource=admin', # Optional
    'database_name': 'test', # Optional
}

# (OR) Connection with URI
config = {
    'connection_string': 'mongodb+srv://username:password@host.gp2xb.mongodb.net/database?retryWrites=true&w=majority'
}

# Creating Instance
mongo_handler = PyMongoBackupRestore(**config)
print('URI -> ', mongo_handler.get_uri()) # Returns the Mongo Host Uri
```


**To check if mongodump and mongorestore commands are working**

This script checks the version of mongodump and mongorestore commands using the --version flag. If the commands are working, it prints a success message; otherwise, it prints an error message.

```python
PyMongoBackupRestore(**config).check_mongodump_mongorestore()
```

---

### Backup Database:

```python
# Backup Full Database
mongo_handler.backup(
    database_name = "DATABASE_NAME",  # Optional if a database_name is provided in the config.
    backup_folder = "BACKUP_FOLDER", 
    compression="gzip" # (Optional)
)

# (OR) Backup a Collection
mongo_handler.backup(
    database_name = "DATABASE_NAME", # Optional if a database_name is provided in the config.
    collection_name = "COLLECTION_NAME", 
    backup_folder = "BACKUP_FOLDER", 
    compression="gzip" # (Optional)
)
```

### Restore Database:

```python
# Restore Full Database
mongo_handler.restore(
    database_name = "DATABASE_NAME", # Target Database Name
    backup_folder = "BACKUP_FOLDER/BACKUP_NAME", 
)

# (OR) Restore a Collection
mongo_handler.restore_collection(
    database_name = "DATABASE_NAME", # Target Database Name
    collection_source = "BACKUP_FOLDER/BACKUP_NAME/file.bson", 
    collection_name = "COLLECTION_NAME", 
)
```

---

---

[![](https://img.shields.io/github/followers/sannjayy?style=social)](https://github.com/sannjayy)  
Developed by *Sanjay Sikdar*.   
- 📫 me@sanjaysikdar.dev




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sannjayy/py-mongo-backup-restore",
    "name": "py-mongo-backup-restore",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10, <4",
    "maintainer_email": "",
    "keywords": "python,mongo,backup,restore,mongodb",
    "author": "Sanjay Sikdar",
    "author_email": "me@sanjaysikdar.dev",
    "download_url": "https://files.pythonhosted.org/packages/5f/7a/608aa4c7016171428bc11bbd6d2f652c7b3853ada8748e342b9cbdd78a7b/py_mongo_backup_restore-2.1.0.tar.gz",
    "platform": null,
    "description": "## Python MongoDB Backup & Restore\r\nPython Library to Backup and Restore MongoDB\r\n\r\nGitHub Repo: [https://github.com/sannjayy/py-mongo-backup-restore](https://github.com/sannjayy/py-mongo-backup-restore)\r\n### Installaion\r\nDo the following in your virtualenv:\r\n\r\n`pip install py-mongo-backup-restore`\r\n\r\n**Import:**\r\n```\r\nfrom py_mongo_backup_restore import PyMongoBackupRestore\r\n```\r\n---\r\n\r\n### Configuration:\r\n```python\r\nfrom py_mongo_backup_restore import PyMongoBackupRestore\r\n\r\n# Database Configuration:\r\nconfig = {\r\n    'scheme': 'mongodb',\r\n    'host': '37.108.158.64:27017',\r\n    'username': 'username',\r\n    'password': 'password',\r\n    'extra_options': '?authSource=admin', # Optional\r\n    'database_name': 'test', # Optional\r\n}\r\n\r\n# (OR) Connection with URI\r\nconfig = {\r\n    'connection_string': 'mongodb+srv://username:password@host.gp2xb.mongodb.net/database?retryWrites=true&w=majority'\r\n}\r\n\r\n# Creating Instance\r\nmongo_handler = PyMongoBackupRestore(**config)\r\nprint('URI -> ', mongo_handler.get_uri()) # Returns the Mongo Host Uri\r\n```\r\n\r\n\r\n**To check if mongodump and mongorestore commands are working**\r\n\r\nThis script checks the version of mongodump and mongorestore commands using the --version flag. If the commands are working, it prints a success message; otherwise, it prints an error message.\r\n\r\n```python\r\nPyMongoBackupRestore(**config).check_mongodump_mongorestore()\r\n```\r\n\r\n---\r\n\r\n### Backup Database:\r\n\r\n```python\r\n# Backup Full Database\r\nmongo_handler.backup(\r\n    database_name = \"DATABASE_NAME\",  # Optional if a database_name is provided in the config.\r\n    backup_folder = \"BACKUP_FOLDER\", \r\n    compression=\"gzip\" # (Optional)\r\n)\r\n\r\n# (OR) Backup a Collection\r\nmongo_handler.backup(\r\n    database_name = \"DATABASE_NAME\", # Optional if a database_name is provided in the config.\r\n    collection_name = \"COLLECTION_NAME\", \r\n    backup_folder = \"BACKUP_FOLDER\", \r\n    compression=\"gzip\" # (Optional)\r\n)\r\n```\r\n\r\n### Restore Database:\r\n\r\n```python\r\n# Restore Full Database\r\nmongo_handler.restore(\r\n    database_name = \"DATABASE_NAME\", # Target Database Name\r\n    backup_folder = \"BACKUP_FOLDER/BACKUP_NAME\", \r\n)\r\n\r\n# (OR) Restore a Collection\r\nmongo_handler.restore_collection(\r\n    database_name = \"DATABASE_NAME\", # Target Database Name\r\n    collection_source = \"BACKUP_FOLDER/BACKUP_NAME/file.bson\", \r\n    collection_name = \"COLLECTION_NAME\", \r\n)\r\n```\r\n\r\n---\r\n\r\n---\r\n\r\n[![](https://img.shields.io/github/followers/sannjayy?style=social)](https://github.com/sannjayy)  \r\nDeveloped by *Sanjay Sikdar*.   \r\n- \ud83d\udceb me@sanjaysikdar.dev\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python Library to Backup and Restore MongoDB",
    "version": "2.1.0",
    "project_urls": {
        "Bug Reports": "https://github.com/sannjayy/py-mongo-backup-restore/issues",
        "Funding": "https://www.paypal.com/paypalme/znasofficial",
        "Homepage": "https://github.com/sannjayy/py-mongo-backup-restore",
        "Say Thanks!": "https://saythanks.io/to/sannjayy",
        "Source": "https://github.com/sannjayy/py-mongo-backup-restore/"
    },
    "split_keywords": [
        "python",
        "mongo",
        "backup",
        "restore",
        "mongodb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f7a608aa4c7016171428bc11bbd6d2f652c7b3853ada8748e342b9cbdd78a7b",
                "md5": "bcc78d13b744efddb08c9189c60f9c4e",
                "sha256": "8bd69df91c01215d62fb7046b41baddf011ccfcf69f7f1cc28df860f6231d568"
            },
            "downloads": -1,
            "filename": "py_mongo_backup_restore-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bcc78d13b744efddb08c9189c60f9c4e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10, <4",
            "size": 4529,
            "upload_time": "2024-03-10T12:56:26",
            "upload_time_iso_8601": "2024-03-10T12:56:26.572339Z",
            "url": "https://files.pythonhosted.org/packages/5f/7a/608aa4c7016171428bc11bbd6d2f652c7b3853ada8748e342b9cbdd78a7b/py_mongo_backup_restore-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-10 12:56:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sannjayy",
    "github_project": "py-mongo-backup-restore",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "py-mongo-backup-restore"
}
        
Elapsed time: 0.21633s