Skip to content

Instantly share code, notes, and snippets.

@icarrr
Last active Apr 4, 2022
Embed
What would you like to do?

Backup and Restore DB Open edX

#!/bin/bash
set -e
localTime=$(date '+%Y%m%d_%H%M%S' -d "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')")
mkdir -p ~/backups/mongodb/dump-$localTime
mongodump --db edxapp --gzip -o ~/backups/mongodb/dump-$localTime -u 'admin' -p 'MONGO_ADMIN_PASSWORD' --authenticationDatabase admin
mongodump --db cs_comments_service --gzip -o ~/backups/mongodb/dump-$localTime -u 'admin' -p 'MONGO_ADMIN_PASSWORD' --authenticationDatabase admin
tar -C ~/backups/mongodb/ -cvpf ~/backups/mongodb/dump-$localTime.tgz dump-$localTime
rm -rf ~/backups/mongodb/dump-$localTime
echo "DONE"
#!/bin/bash
set -e
localTime=$(date '+%Y%m%d_%H%M%S' -d "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')")
mkdir -p ~/backups/mysql/backups-$localTime
mysqldump -u root --databases edxapp > ~/backups/mysql/backups-$localTime/edxapp_backup.sql
mysqldump -u root --databases edxapp_csmh > ~/backups/mysql/backups-$localTime/edxapp_csmh_backup.sql
tar -C ~/backups/mysql/ -cvpf ~/backups/mysql/backups-$localTime.tgz backups-$localTime
rm -rf ~/backups/mysql/backups-$localTime
echo "DONE"
#!/bin/bash
set -e
mongorestore --gzip --db 'edxapp' ~/backups/edxapp -u 'admin' -p 'MONGO_ADMIN_PASSWORD' --authenticationDatabase admin
mongorestore --gzip --db 'cs_comments_service' ~/backups/cs_comments_service -u 'admin' -p 'MONGO_ADMIN_PASSWORD' --authenticationDatabase admin
#!/bin/bash
set -e
mysql -u root -e "drop database edxapp;"
mysql -u root -e "drop database edxapp_csmh;"
mysql -u root -e "create database edxapp;"
mysql -u root -e "create database edxapp_csmh;"
mysql -u root edxapp < ~/extract-vania/name_backup/edxapp_backup.sql
mysql -u root edxapp < ~/extract-vania/name_backup/edxapp_csmh_backup.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment