MySQL backup db script


You want to back up your mysql database.



This script is good for backups, as it will generate a dump – zipped and as the day of the week is used (in the backup file name), automatically rolls every 7 days.

Run it daily or every other day. If you want a months worth, guess can just change the date command, etc.




[ $# -ne 1 ] && {
    echo "Usage: $0 db"
    exit 1

dbd="/PATH_TO_YOUR_BUS/$db.$(/bin/date +%a)"    # set the path
alias mysqldump="/usr/bin/mysqldump"            # you may need to modify this
alias gzip="/bin/gzip"                          # may need to change this too
# set your password and user
mysqldump --user=root --password=your_password $db > $dbd 
gzip --best --force $dbd
exit 0


[tags]MySQL, Backups[/tags]

If you have found my website useful, please consider buying me a coffee below 😉

Leave a Reply

Your email address will not be published. Required fields are marked *