bash script to backup mysql

bash script to backup mysql
sleepynerd@narcolepticnerd:~
sleepynerd@narcolepticnerd : ~ $ cat $HOME/public_html/posts/bash-script-to-backup-mysql.txt.txt | parse_content --format=auto
sleepynerd@narcolepticnerd : ~ $

#!/bin/bash
mydate=$(date | tr " " "-");
mydb="yourdbname"
mysqldump $mydb > $mydb-$mydate.sql
gzip $mydb-$mydate.sql

Make a user that only has dump privileges
name it backup.sh Edit the ~/.my.cnf and add the following

[mysqldump]
user=theusername
password=thepassword

crontab -e

0 * * * * sh backup.sh

this will run the backup hourly.

Digital Community Builder, Sleepy Coder, Weather & News Nerd

Connect with Me