【Linux中Mysql数据库之定时备份】

一、Linux下面Mysql数据库定时备份脚本

[root@node1 ~]# vi backupMysql.sh
#!/bin/bash
# Name:bakmysql.sh
# This is a ShellScript For Auto DB Backup and Delete old Backup
#@author gaojingsong
#@email:525354786

#backup dir
backupdir=/home/mysqlbackup
#filename
time=`date +%Y_%m_%d_%H_%M_%S `
#mysql dbname
db_name=test
#mysql username
db_user=root
#mysql passwd
db_pass=123456

#begin backup
mysqldump -u $db_user -p$db_pass $db_name | gzip > $backupdir/$db_name$time.sql.gz
#end backup


#delete the old backup the day before 10 days
find $backupdir -name $db_name"*.sql.gz" -type f -ctime  +10  -exec rm -rf {} \;

实际应用中数据量非常大,可以进行增量备份;也可以进行物理备份即拷贝文件目录。

你可能感兴趣的:(【Linux中Mysql数据库之定时备份】)