Skip to content

Instantly share code, notes, and snippets.

@balos1
Created January 12, 2017 06:51
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 balos1/07ca2126946ac6c44ebe4ffddcfc85d4 to your computer and use it in GitHub Desktop.
Save balos1/07ca2126946ac6c44ebe4ffddcfc85d4 to your computer and use it in GitHub Desktop.
Script to backup MySQL database. Can be used with cron for automatic backups.
#!/bin/sh
DAY=`/bin/date +%Y%m%d`
PAST_DAY=`/bin/date -d '5 days ago' +%Y%m%d`
mysqldump DATABASE -u root -pPASSWORD > /path/to/it/DATABASE.$DAY.sql
rm -f /path/to/it/DATABASE.$PAST_DAY.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment