MySQL backup db script

Problem

You want to back up your mysql database.



Solution

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.



Example


#!/bin/zsh[ $# -ne 1 ] && {    echo "Usage: $0 db"    exit 1}db=$1dbd="/PATH_TO_YOUR_BUS/$db.$(/bin/date +%a)"    # set the pathalias mysqldump="/usr/bin/mysqldump"            # you may need to modify thisalias gzip="/bin/gzip"                          # may need to change this too# set your password and usermysqldump --user=root --password=your_password $db > $dbd gzip --best --force $dbdexit 0


Reference



Leave a Reply

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