首页 > 数据库 > mysql教程 > MySQL backup and cleanup bash scripts with mydumper_MySQL

MySQL backup and cleanup bash scripts with mydumper_MySQL

WBOY
发布: 2016-05-31 08:50:28
原创
965 人浏览过

bitsCN.com

1. Backup script

#!/bin/sh# Fri Jun 27 10:44:49 2014# done by dragkh# usage: # cat /etc/cron.d/backupmysql # 03***	 root	/root/bin/clean.backup.hyperion.mysql.mydumper.daily.sh >>/var/log/clean.backup.${HOSTNAME}.mysql.mydumper.daily.log 2>&1# 353***	 root	/root/bin/backup.hyperion.mysql.mydumper.daily.sh >> /var/log/backup.${HOSTNAME}.mysql.mydumper.daily.log 2>&1ROOT_BACKUP_DIR="/home/mydumper"seik_date () {if [ -z $1 ]then# cdate=`date +%Y-%m-%d/ %H:%M:%S/ %Z`; export cdate; echo $cdatecdate=`date -R`; export cdate; echo $cdateelseif [ -z ${2} ]thencdate=`date +%Y-%m-%d.%H.%M.%S`; export cdate; echo $cdateelsecdate=`date "+%Y-%m-%d %H:%M:%S"`; export cdate; echo $cdatefifi}function check_dir { test ! -d "${1}" && mkdir -p "${1}"}function set_cpu_threads {	# set the threads one less than the existing 	threads=$(cat /proc/cpuinfo|grep processor | tail -1 | awk '{print $3}')	test $threads -lt 1 && threads=1}function dump_schema {	mysqldump -d --dump-date --all-databases > ${DATA_DIR}/${HOSTNAME}.only.sql}function dump_data {	echo "$(seik_date f) : executing : mydumper -o $DATA_DIR --long-query-guard 120 -r 100000 -c -e -m -L ${DATA_DIR}/mysql-backup.log -t ${threads} -v 3"	mydumper -o $DATA_DIR --long-query-guard 120 -r 100000 -c -e -m -L ${DATA_DIR}/mysql-backup.log -t ${threads} -v 3}DATA_DIR="${ROOT_BACKUP_DIR}/$(seik_date d)"check_dir "${DATA_DIR}" && echo "$(seik_date f) : ${DATA_DIR} is missing, creating it now .."set_cpu_threadsecho "$(seik_date f) : star dumping the schema at ${DATA_DIR}.."dump_schema && echo "$(seik_date f) : end dumping the schema at ${DATA_DIR} .."echo "$(seik_date f) : start dumping the data at ${DATA_DIR} via ${threads} parallel threads .."dump_data && echo "$(seik_date f) : end dumping the data at ${DATA_DIR} via ${threads} parallel threads .."
登录后复制

2. Clean up script keeping always backup directories intact

#!/bin/bash# Sat Jun 28 03:16:38 EEST 2014# done by dragkh# usage: # cat /etc/cron.d/backupmysql# 0 3 * * * root/root/bin/clean.backup.hyperion.mysql.mydumper.daily.sh >> /var/log/clean.backup.${HOSTNAME}.mysql.mydumper.daily.log 2>&1# 353* * * root/root/bin/backup.hyperion.mysql.mydumper.daily.sh >> /var/log/backup.${HOSTNAME}.mysql.mydumper.daily.log 2>&1ROOT_BACKUP_DIR="/home/mydumper"seik_date () {if [ -z $1 ]thencdate=`date -R`; export cdate; echo $cdateelseif [ -z ${2} ]thencdate=`date +%Y-%m-%d.%H.%M.%S`; export cdate; echo $cdateelsecdate=`date "+%Y-%m-%d %H:%M:%S"`; export cdate; echo $cdatefifi}day_limit=7;ls -t ${ROOT_BACKUP_DIR} | /while read dirdo ((dir_num++))test $dir_num -gt $day_limit && test -d "${ROOT_BACKUP_DIR}/${dir}" &&rm -rf "${dir}" && echo "$(seik_date d) : removed [${dir_num}]::[${dir}]" && continue test -d "${ROOT_BACKUP_DIR}/${dir}" && echo "$(seik_date d) : skipping [${dir_num}]::[${dir}]"done
登录后复制
bitsCN.com
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板