如何监视常规的MySQL备份。

我是一名开发人员,我正在与我的系统pipe理员讨论如何备份我们正在使用的MySQL数据库。

之前的系统pipe理员告诉我他已经开始备份数据库,但是那个不熟悉的人会帮我开发一个脚本。

首先,开发人员应该对数据库备份负责,这是正常的吗? 我工作过的每一个地方,系统pipe理员都照顾好了,发展起来了。

所以目前我有一个Perl脚本调用一个mysql转储,并将其与代码一起备份。 现在由于某种原因,在晚上的中间备份失败,并创build数据库的截断版本。 我把它作为一个临时的解决scheme来开发,几周前当我需要时,备份失败了。 由于这个原因,我宁愿sysadmin承担责任,因为我有代码开发,并不需要每天检查cron作业输出。

那么,每隔一小时备份一次数据库的可靠方法是什么,如果备份失败,会发出警告。

我所看到的典型场景是企业主或其代表决定保留,可接受的数据和恢复点的目标,因为所有者是支付所得到的账单的人。

DBA(和/或sysadmin)了解应用程序configuration文件(复杂事务或简单的表更新,备份窗口,数据库大小,数据增长,更改的行数等),并决定一个适当的备份策略以满足那些要求。

在这一点上,企业主通常会决定最初的铂金备份要求太贵,所以冲洗和重复。

开发人员甚至不能访问生产系统,即使他们这样做; 他们不负责每日备份。 (尽pipe在对数据库结构进行任何操作之前确保备份是一种很好的做法)。

所以我同意你的看法,让别人去解决问题。


如果您的应用程序正常运行更新多个表的事务,则您希望使用表locking选项运行mysqldump以确保一致性。 但是,这将阻止在备份工作期间对数据库的所有更新,所以每小时这样做往往是一个坏主意。

二进制日志允许时间点恢复和增量备份。

看看http://dev.mysql.com/doc/refman/5.7/en/backup-methods.html


一个简单的脚本,用于备份MySQL服务器上的所有数据库,每个数据库都是一个单独的文件。 只有在出现问题的情况下才会通过电子邮件发送给您。 只要cron运行,备份将被创build。 一如既往,也testing你的恢复能力!

#!/bin/bash # Simple script to create logical backups of all MySQL databases on # a server. by http://serverfault.com/users/37681/hbruijn # Free to use and modify as neeeded. #====================================================================== # Define paths to system binaries MYSQL="/usr/bin/mysql" MYSQLDUMP="/usr/bin/mysqldump" GZIP="/bin/gzip" MAIL="/bin/mailx" # MySQL credentials used for reading the databases. # either the MySQL DBA account "root" # or alternatively create a dedicated read-only backup user # with the following GRANT statement: # mysql> GRANT SELECT,RELOAD,SUPER,REPLICATION CLIENT ON *.* TO \ # backupuser@<this IP or localhost> identified by 'Very_s3cr3t_passW0rd'; MYHOST="localhost" # localhost or remote ip-address MYUSER="backupuser" MYPASS="Very_s3cr3t_passW0rd" # Local filesystem or network share to dump back-ups # Good practice to have file back-ups on their own filesystem # and not on the root filesystem. MYBAKDIR="/backups" # Keep 1 week worth of MySQL backups under $MYBAKDIR MYDIR=$(date +MySQL/%A) # Mail errors to somebody in charge [email protected] # The rest shouldn't need much tuning #===================================================================== errormail(){ cat << EOF | $MAIL -s "MySQL back-up failed !" $ERROR_RCPT This is an automatic warning message. The MySQL back-up on server: $(hostname) has failed with the following errors: $1 Please take appropiate action. Thanks in advance. EOF exit 1 ; } if ! test -d $MYBAKDIR ; then mkdir -p $MYBAKDIR || errormail "Backup directory $MYBAKDIR does not exist and could not be created." fi if test -d "$MYBAKDIR/$MYDIR" ; then rm -rf "$MYBAKDIR/$MYDIR" || errormail "Expired backups from $MYBAKDIR/$MYDIR could not be removed." fi mkdir -p "$MYBAKDIR/$MYDIR" || errormail "Todays backup directory $MYBAKDIR/$MYDIR could not be created." # Generate list with all databases DATABASES=$(echo "show databases" | $MYSQL -h $MYHOST -u $MYUSER -p$MYPASS |grep -v ^Database$) || errormail "Unable to connect to MySQL database server on $MYHOST please check the supplied credentials" # Make a logical backup of each database for DB in $DATABASES do $MYSQLDUMP -h $MYHOST -u $MYUSER -p$MYPASS --opt --single-transaction $DB > $MYBAKDIR/$MYDIR/$DB.sql || errormail "Unable to create backup from $DB " $GZIP $MYBAKDIR/$MYDIR/$DB.sql || errormail "Unable to compress $MYBAKDIR/$MYDIR/$DB.sql " done