#!/bin/sh
# File: /data/backup/dhdatabak.sh
# Write by:sandy
# Last Modify:2013-09-11
# Database info
DB_NAME="osite"
DB_USER="user"
DB_PASS="pwd"
# Others vars
BCK_DIR="/data/backup/dhdata"
DATE=`date "+%Y%m%d-%H_%M"`
DAYS=30
LOGFILE=/data/backup/logs/dhbackup.log
# TODO
mysqldump -R --opt -u$DB_USER -p$DB_PASS $DB_NAME > $BCK_DIR/dh_$DATE.sql
echo "$date Database:$databases backup success!">>$LOGFILE
cd $BCK_DIR
tar -zcvf dh$DATE.tar.gz dh_$DATE.sql
rm $BCK_DIR/dh_$DATE.sql
find $BCK_DIR -name "dh*" -type f -mtime +$DAYS -exec rm {} \;
10 1 * * * root /data/backup/dhdatabak.sh >> /data/backup/logs/cronlog.txt 2>&1
本文出自 “黄怡善的运维博客” 博客,请务必保留此出处http://linuxpython.blog.51cto.com/10015972/1653085
原文地址:http://linuxpython.blog.51cto.com/10015972/1653085