定时备份mysql数据

#!/bin/bash

DB_USER=root
DB_PASSWD=""
#需要备份的数据库名
DATABASES="bigamer bigamer_ucenter bigamer_anwsion bigamer_passport"
BACKUP_DIR="/home/backup/mysql/"
DATE=`date '+%Y%m%d'`
DUMPFILE=$DATE.sql
ARCHIVEFILE=$DUMPFILE.tar.gz
DUMP_ARGS="-u $DB_USER -p $DB_PASSWD --add-drop-table --add-drop-database -B $DATABASES"
DUMP_BIN=`which mysqldump`

if [ ! -d $BACKUP_DIR ]; then
mkdir -p "$BACKUP_DIR"
fi

cd $BACKUP_DIR

$DUMP_BIN $DUMP_ARGS > $DUMPFILE

if [[ $? == 0 ]]; then
tar czf $ARCHIVEFILE $DUMPFILE
    rm -f $DUMPFILE
fi

#清理五天前备份的数据
find $BACKUP_DIR -name "*.sql.tar.gz" -type f -mtime +5 -exec rm {} \; > /dev/null 2>&1

echo "Backup Process Done"

Leave a Comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: