Skrip berguna untuk backup Mysql setiap hari

Posted: February 19, 2009 in Debian, Slackware

Copy from http://yusshalimee.blogspot.com/

Skrip ini aku guna kat server aku.. backup mysql setiap hari. Hanya perlu ubah pada bahagian setting sahaja. chmod dan set cron untuk daily run

=========== mula ==============

#!/bin/bash

##### SETTING #####
MYUSER=”dbuser”
MYPWD=”password”
DB=”database”
DIR_PATH=”/var/mysql-backup”
FAIL=mybck_$(date +%d-%m-%Y)

###################

#check DIR_PATH
if [ ! -d $DIR_PATH ]
then
mkdir $DIR_PATH
fi

#Running MySQL dump
cd /tmp
mysqldump -c -x –add-drop-table –add-locks –database $DB -u $MYUSER -p$MYPWD > $FAIL.sql

#Compress result
if [ -e $DIR_PATH/mytoday_$(date +%d-)* ]
then
rm -f $DIR_PATH/mytoday_$(date +%d-)*
tar -jcf $DIR_PATH/$FAIL.tgz $FAIL.sql
rm -f $DIR_PATH/latest.tgz
ln -s $DIR_PATH/$FAIL.tgz $DIR_PATH/latest.tgz
else
tar -jcf $DIR_PATH/$FAIL.tgz $FAIL.sql
rm -f $DIR_PATH/latest.tgz
ln -s $DIR_PATH/$FAIL.tgz $DIR_PATH/latest.tgz
fi
rm -f $FAIL.sql

===================== tamat ====================

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s