Change website

From Jan 16 2015,


All post content will be move to we's offical website with many content...

Can access website here: http://justox.com

Thanks for your visit!

Thursday 19 December 2013

How To Backup MySQL databases using a shell scripts

MySQL is one of the most popular open source database management system for the development of interactive websites.
If your server stores its sensitive data in a MySQL database, you will most definitely want to backup that information so that it can be restored in case of any disaster.
Below is a backup script for MySQL databases (please make sure you will change MYSQL_PASS):

01#!/bin/sh
02# backup mysql databases shell script
03# UNIX LINUX BSD
04# by Adi http://blog.up-link.ro
05# March 2010
06 
07DATE=$(date +%Y-%m-%d)
08MYSQL=$(which mysql)
09MYSQLDUMP=$(which mysqldump)
10MYSQL_USER="root"
11MYSQL_PASS="password"
12HOSTNAME=$(hostname)
13GZIP=$(which gzip)
14ARG="-u $MYSQL_USER -p$MYSQL_PASS"
15DATABASES=$($MYSQL $ARG -s -e "SHOW DATABASES;")
16BACKUP_PATH="/home/backup/$DATE/mysql"
17 
18! [ -d $BACKUP_PATH ] && mkdir -p $BACKUP_PATH
19 
20for DB in $DATABASES
21do
22BACKUP_FILE="$BACKUP_PATH/$HOSTNAME-mysql-$DB-$DATE.sql.gz"
23$MYSQLDUMP $ARG $DB | $GZIP -9 > $BACKUP_FILE
24done

No comments:

Post a Comment