Last active
December 5, 2023 14:30
-
-
Save sethigoldy/e241da174be63170e628a588a4be49ff to your computer and use it in GitHub Desktop.
Incremental backups with mongodump and mongorestore
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
Note: | |
Oplog should be big enough from the last full backup till the next backup so that mongodump can copy all the changes happened from the last backup. | |
Also, this is an experimental way of doing backup and restore, not thouroughly tested. | |
Mongorestore: | |
mongorestore -h localhost --oplogReplay --port 27017 --oplogFile=backups/incremental/oplog.bson --dir backups/base |
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
#!/bin/bash | |
New_DATE=$(date +%s) | |
mongodump -h localhost --port 27017 -o backups/base | |
Old_DATE=$(cat query.js | awk -F: '{print $5}' | cut -c 1-10) | |
awk -v old="$Old_DATE" -v new="$New_DATE" '{gsub("\"t\":" old ",", "\"t\":" new ",")} 1' query.js > temp.js && mv temp.js query.js |
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
#!/bin/bash | |
rm -rf backups/incremental | |
mkdir -p backups/incremental/ | |
mongodump -h localhost -d local -c oplog.rs --queryFile query.js --port 27017 -o - > backups/incremental/oplog.bson |
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
{"ts":{"$gte":{"$timestamp":{"t":0000000000,"i":1}}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment