Skip to main content

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.decrypt_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

Metadata

Release files for mongogbackup 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongogbackup 0.1.1
File Size Uploaded
mongogbackup-0.1.1.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongogbackup 0.1.1
File Interpreter ABI Platform
mongogbackup-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.3 kB

Release files / mongogbackup-0.1.1.tar.gz

Download URL mongogbackup-0.1.1.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
3a046364de600c421ac3e0440e1eaf09ce709fab76239f0d1ee567fc75d41ddc
BLAKE2b-256 checksum
How to use checksums
d30083c9d54e125b1b74a0075aa2417db6c69530986a838cc4929d977dcd86a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.0

Release files / mongogbackup-0.1.1-py3-none-any.whl

Download URL mongogbackup-0.1.1-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f11f91cc7a9e6a6d1f88392a4f3837720769da3c71577acd06373d41d244ab28
BLAKE2b-256 checksum
How to use checksums
deda8b13a9f559e7a13631a2d62f2ff43509167e81c81a48163f46623794dbda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page