Skip to content

Instantly share code, notes, and snippets.

@lucis
Last active June 14, 2023 20:31
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucis/74954565122710a690bfa5a4c9ca2e9b to your computer and use it in GitHub Desktop.
Save lucis/74954565122710a690bfa5a4c9ca2e9b to your computer and use it in GitHub Desktop.
Mongo DB Backup + Gdrive Upload
#!/bin/sh
cd /tmp
FILE=`date +%m%d%y%S`
DEST=mongodb-backup/$FILE.gz
DB_NAME=database-name
# This PARENT_FOLDER is a reference to a Google Drive folder in your account (like, "my-backups").
# Use gdrive list to get the ID of the folder you want
PARENT_FOLDER=186AdURawhC3qJDL7OkGL9ueJmU44pteV
mongodump -d $DB_NAME --archive=$DEST --gzip
gdrive --service-account sa.json upload -p $PARENT_FOLDER $DEST
ls mongodb-backup | grep -v $FILE.gz | xargs rm
@Hafizjunaid971
Copy link

Hafizjunaid971 commented Jul 15, 2021

please share details to backup

@theabhinavdas
Copy link

Thanks @lucis, love how simple this is :)

@mahmed0715
Copy link

a more detail would help using this script. how drive works..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment