Skip to content

Instantly share code, notes, and snippets.

@naxIO
Created June 19, 2013 11:36
Show Gist options
  • Save naxIO/5813620 to your computer and use it in GitHub Desktop.
Save naxIO/5813620 to your computer and use it in GitHub Desktop.
Simple mysql dump shell script, that uses the actual date for the file. Works with crontab! (Date escaped). Note that there is no space between the -p and the password.
#!/bin/bash
NOW=`/bin/date +"%m%d%Y-%H%M%S"`
if [[ "$?" != "0" ]]; then
NOW="UNKNOWN_DATE"
fi
mysqldump -h hostname -u username -pPassword databasename > /opt/databasebackup/$NOW.sql
if [[ "$?" != "0" ]]; then
echo "$0: backup failed with error code $?"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment