Skip to main content

Securely Backup MongoDB to Google Drive

Project description

mongogbackup

Secure Mongo DB backups on Google Drive

Installation

$ pip install mongogbackup

Usage

Import

from  mongogbackup import MongoConfig, MongoGBackup

Initialization

mongo_config = MongoConfig(
                                db_name='your_db',
                                host='localhost',
                                port=27017,
                                # optional parameters below
                                username='root',
                                password='password',
                                auth_db='admin'
                            )
backup_handler =MongoGBackup(
                            mongoConfig=mongo_config,
                            credentials_file='path/credentials.json',  
                            key='fernet_key'
                        )
gdrive = GoogleDriveHandler(
                             credentials_file='path/credentials.json',
                             parent_id = target_folder_id,
                             file_name = name_of_the_file_you_want_to_upload,
                             num_files = how_many_files_you_want_to_keep_in_the_rotating_file_handler               
)

Creating dump

backup_handler.backups.backup(dir='backup_path/dump/')

Compressing the dump

backup_handler.targz.pack(source_path='backup_path/dump/', output_path='filename.tar.gz')

Encrypting the dump

backup_handler.encrypt.encrypt_file('filename.tar.gz', 'destination.file')

Uploading to Google Drive

Add your credentials.json file to your project (you can generate this on Google Cloud Console)

Simple upload to google drive

gdrive.upload_file_to_drive(file_name, parent_id)

Delete all previous files with same name and upload to Google Drive

gdrive.overwrite_and_upload_to_drive(file_name, parent_id)

Upload to Google Drive with a rotating file handler

gdrive.upload_to_drive_with_rfh(file_name, parent_id, num_files)

Restore Backups

Download the backup file from google drive (say: backup.encr)

Decrypt the file

backup_handler.encrypt.encrypt_file('backup.encr', 'filename.tar.gz')

Decompressing the tar-gz dump

backup_handler.targz.unpack(source_path='filename.tar.gz', output_path='backup_dir/dump/')

Restoring the dump

backup_handler.backups.restore(bck_dir='backup_dir/dump/')

Hash Checks

To ensure that your backup file has not been tampered with, you can perform a SHA-256 hash check.

backup_handler.hash.generate_file_hash('source.file')

You can also save the hash into a txt file by executing

backup_handler.hash.save('hash.txt')

or print the hash by executing

print(backup_handler.hash.last_hash())

You can also compare the current generated hash with any other string using

backup_handler.hash.compare_generated('hash-string')
# returns True or False on comparision

Made with ❤️ by DevCom, 2024

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

mongogbackup-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

mongogbackup-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file mongogbackup-0.1.0.tar.gz.

File metadata

  • Download URL: mongogbackup-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for mongogbackup-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a9f6987939456d3a7aa36fde9955389acc5946424b62860b4b79583a75bca2b1
MD5 d6929ac804f7d9688c171d5c346ac387
BLAKE2b-256 8e7e27760ba8d357633666f19a0660ea250dd9c49ad06c635a025efb34883cc5

See more details on using hashes here.

Provenance

File details

Details for the file mongogbackup-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mongogbackup-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.0

File hashes

Hashes for mongogbackup-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4275099bce1a66e4a71a74a5cececa3e6454f3f670e9544949e2ead42025ebf3
MD5 e1ec4dd030f203d1ad3193c2e18342d6
BLAKE2b-256 4806e5d99e1aa7399bbe145e1a280571df5f70079fca227a002dcbd8358735cd

See more details on using hashes here.

Provenance

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