2011-01-25

[Shell] backup mysql data by day (note)

#!/bin/bash

PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

DATE=$(date +%Y%m%d)
TARGET=/root/my_backup
OPT="--opt -c -n -t --skip-triggers"
ID="root"
PW="1234"
DB="mydb"

TMP=$TARGET/$DB.$DATE.bak.sql"
BAK=$TARGET/$DB.$DATE.bak.tgz"

#==( Backup MySQL )=======================================
mysqldump -u$ID -P$PW $OPT $DB > $TMP
tar -zcf $BAK $TMP
rm $TMP

exit 0

0 回應: