How do I check if a database exists in bash?
I'm planning to make an automated backup script, where each website's db name is:
(siteName) mysite.com = mysite_com (dbName)
You can check if a file exists with the -e bash command. MongoDB creates a Namespace file for each database, so search for those. Something like
if [ -e /data/db/$DBNAME.ns ]; then
`mongodump -d $DBNAME --out /backup/directory`
fi
Assuming your data is stored in /data/db
Have a look at the mongodump command which can be used to backup data from your mongo db instance http://www.mongodb.org/display/DOCS/Backups
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With