Last active
January 8, 2022 00:44
-
-
Save valorad/f425126ed95ff1b30ddd4b5d64599009 to your computer and use it in GitHub Desktop.
Mongo Backup Collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoContainerOutput="/path/to/container/output/folder" | |
hostOutput="/path/to/host/output/folder" | |
mongoUser="root" | |
mongoPassword='mongo-db-user-password' | |
mongoHost="127.0.0.1:27017" | |
mongoCollectionAuth="admin" | |
mongoCollectionDB="dbCollectionName" | |
dockerContainer="mongo_5_1" | |
mongoURI="mongodb://$mongoUser:$mongoPassword@$mongoHost/$mongoCollectionDB?authSource=$mongoCollectionAuth" | |
rm -rf $hostOutput/"$mongoCollectionDB" | |
docker exec -it $dockerContainer mongodump --uri $mongoURI -o $mongoContainerOutput | |
sudo chown $UID:$UID -R $hostOutput/"$mongoCollectionDB" | |
tar -czvf $hostOutput/"$mongoCollectionDB-$(date '+%Y%m%d-%s').tar.gz" -C "$hostOutput/$mongoCollectionDB/" . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment