Skip to content

Instantly share code, notes, and snippets.

@oscardelgado
Last active March 14, 2018 08:59
Show Gist options
  • Save oscardelgado/fa2138572b8f890f1d17a0b4bc416a93 to your computer and use it in GitHub Desktop.
Save oscardelgado/fa2138572b8f890f1d17a0b4bc416a93 to your computer and use it in GitHub Desktop.
How to upload a backup of your MySQL BD in OpenShift 3 to your Dropbox account
Based on https://medyo.github.io/2017/backup-openshift-database/ (was for OpenShift 2)
See https://github.com/andreafabrizi/Dropbox-Uploader
Steps:
1 - Create new Dropbox App and get the token
Create A new Dropbox App Through Dropbox Developers
Select Dropbox API -> App Folder then name your app
Once created, Go to Generated access token section and click generate
Now you got the token !
2 - Start a shell session in your MySQL Pod:
> oc get pods
> oc rsh <mysql_pod>
(Or, from your Openshift management console, go to your MySQL Pod and open the Terminal Tab).
Then:
cd /tmp
mysqldump -u $MYSQL_USER --password=$MYSQL_PASSWORD --all-databases > mysqldump_$(date -Isecond)
gzip mysqldump_<date>
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
chmod +x dropbox_uploader.sh
./dropbox_uploader.sh
./dropbox_uploader.sh upload mysqldump_<date>.gz mysqldump_<date>.gz
You can automate it and add schedule it as a cron job.
Or:
nohup sh -c 'while : ; do echo "Starting backup..." && date && mysqldump -u $MYSQL_USER --password=$MYSQL_PASSWORD --all-databases > mysqldump && gzip mysqldump && ./dropbox_uploader.sh
upload mysqldump.gz mysqldump.gz && rm mysqldump.gz && sleep 1d; done' &> automatic_mysql_dump.log&
Enjoy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment