cat backup_linuxmysql_db-rsc_akcms.sh
#!/bin/bash
#Set the backup filename
DATA=`date +%Y%m%d`
FILENAME="linuxmysql_db_bak_$DATA.sql"
BACKUPDIR="/backup/linuxmysql_db_backup/"
#Database parameter
DBUSER="root"
DBPWD="ruanganlove999"
DBNAME="rsc_akcms"
HOST="localhost"
#Change to the root directory
cd /
#GZIP tool for compression
#The -f parameter will make sure that gzip will overwrite existing files
GZIP="/bin/gzip -f"
#execute the database dump
mysqldump --host=$HOST --user=$DBUSER --password=$DBPWD --add-drop-table --database $DBNAME >$BACKUPDIR$FILENAME
$GZIP $BACKUPDIR$FILENAME
#Delete old backup older than 1 week
find /backup/linuxmysql_db_backup/*.sql.gz -mtime +7 -exec rm {} \;