mysql backup 脚本
- - ITeye博客网上备份脚本很多,但考虑都不周全. 保证创建备份文件只能是创建者跟root可以访问,其他用户没有权限,保证了数据库备份的安全. 上面脚本是负责备份的份数管理,. 已有 0 人发表留言,猛击->> 这里<<-参与讨论. —软件人才免语言低担保 赴美带薪读研.
网上备份脚本很多,但考虑都不周全。这里增加了
umask 0077
保证创建备份文件只能是创建者跟root可以访问,其他用户没有权限,保证了数据库备份的安全。
find $BACKUP_DIR -type f -mtime +$COPIES -delete
上面脚本是负责备份的份数管理,
#!/bin/bash ################################### # $Id: backup 380 2012-04-02 10:38:59Z netkiller $ # Author: [email protected] # Home: http://netkiller.github.com ################################### BACKUP_HOST="localhost" BACKUP_USER="root" BACKUP_PASS="" BACKUP_DIR=/opt/backup BACKUP_DBNAME="test neo" #Number of copies COPIES=7 #################################### MYSQLDUMP="mysqldump" #TIMEPOINT=$(date -u +%Y-%m-%d) TIMEPOINT=$(date -u +%Y-%m-%d.%H:%M:%S) MYSQLDUMP_OPTS="-h $BACKUP_HOST -u$BACKUP_USER -p$BACKUP_PASS" #################################### umask 0077 test ! -d "$BACKUP_DIR" && mkdir -p "$BACKUP_DIR" test ! -w $BACKUP_DIR && echo "Error: $BACKUP_DIR is un-writeable." && exit 0 for dbname in $BACKUP_DBNAME do test ! -d "$BACKUP_DIR/$dbname" && mkdir -p "$BACKUP_DIR/$dbname" $MYSQLDUMP $MYSQLDUMP_OPTS $dbname | gzip > $BACKUP_DIR/$dbname/$dbname.$TIMEPOINT.sql.gz done find $BACKUP_DIR -type f -mtime +$COPIES -delete