Skip to content

Instantly share code, notes, and snippets.

@donilan
Created May 14, 2020 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donilan/0097de211cfff8a3a6ad7e42550d8cba to your computer and use it in GitHub Desktop.
Save donilan/0097de211cfff8a3a6ad7e42550d8cba to your computer and use it in GitHub Desktop.
dump/backup mysql database in docker way
#!/usr/bin/env bash
docker run --rm mysql:5.7 mysqldump \
-uUSERNAME \
-hmysq.example.com \
-pPASSWORD database_name | gzip > /path/to/your/backup/folder/backup_$(date +"%Y%m%d_%H%M%S").sql.gz
# only keep 5 backups
ls -1tr | head -n -5 | xargs -d '\n' rm -f --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment