Giter Site home page Giter Site logo

devcom-iitb / mongogbackup Goto Github PK

View Code? Open in Web Editor NEW
2.0 0.0 0.0 18.73 MB

Remote Mongo DB backup on Google Drive

Home Page: https://pypi.org/project/mongogbackup/

License: MIT License

Python 95.95% Batchfile 1.31% PowerShell 1.50% Shell 1.24%
backup gdrive mongodb

mongogbackup's Introduction

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

mongogbackup's People

Contributors

ananyac9 avatar keymii avatar https-kanika avatar

Stargazers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.