mysqldump –-all-databases –-opt > db.sql |
mysqldump –-databases –-opt mydb > db.sql |
mysql –u root –ppassword
#进入mysql命令模式
mysql>source db.sql |
修改/etc/my.cnf:,增加一下内容: [mysqld] server-id=1 log-bin=/opt/mysql_backup/date_backup #可以自己指定 log-bin-index=/opt/mysql_backup/date_backup.index
重启mysql: /etc/init.d/mysqld restart |
mysql –u root –ppassword –e “flush logs” |
mysqlbinlog date_backup.000001 | mysql –u root -ppassword |
mysqlhotcopy -u=root -p=password –-addtodest dbname /home/mysql_backup/ |
cp -rf /home/mysql_backup/dbname /var/lib/mysql/ chown –R mysql:mysql /var/lib/mysql/dbname |
[mysqld] server-id=1 log-bin=/opt/mysql_backup/date_backup log-bin-index=/opt/mysql_backup/date_backup.index |
mkdir -pv /opt/mysql_backup chown mysql /opt/mysql_backup mkdir –pv /home/mysql_backup/{1..12} /etc/init.d/mysqld restart |
#!/bin/bash MY_PASS='12Nm34' ORIG_DIR='/opt/mysql_backup/' INDEX_FILE="${ORIG_DIR}/date_backup.index" BACKUP_DIR='/home/mysql_backup' DATE=`date +%F` CURRENT_DAY=`date +%d` CURRENT_MONTH=`date +%m` DB="cacti"
if [ "$CURRENT_DAY" = "01" ] then mysqldump -p${MY_PASS} -F -x --databases ${DB} > ${BACKUP_DIR}/${CURRENT_MONTH}/Full_backup_${DATE}
else
LOG_FILE=`find "${ORIG_DIR}" -name "*log*" -type f -cmin -1439` echo "$LOG_FILE" > /tmp/mysql.index mysql -p${MY_PASS} -e "flush logs" count=0 for file in $LOG_FILE do cp $file ${BACKUP_DIR}/${CURRENT_MONTH}/date_backup-${DATE}_${count} count=$((count+1)) done fi |