设为首页 收藏本站
查看: 1524|回复: 0

[经验分享] mysqldump 备份常用选项以及备份脚本

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-18 12:45:42 | 显示全部楼层 |阅读模式
1、备份命令:
# mysqldump -u'root'  -p'12345' -h 127.0.0.1 \
     -q --single-transaction -R -E \
     --triggers --default-character-set=utf8 \
     -B test | gzip > test.`date +%F_%T`.sql
2、备份脚本:
# cat /dbback.sh
#!/bin/bash

datetime=`date +%F_%T`
dbname=(mysql test )
echo $datetime  > /backdb.log

for db in ${dbname[*]}
    do
echo "############################## db back $db  begin time is $(date +%F_%T) ##############################" >> /backdb.log


mysqldump -u'root'  -p'12345' -h 127.0.0.1  -q --single-transaction -R -E --triggers --default-character-set=utf8 -B ${db} | gzip  > /${db}.$(date +%F_%T).sql.gz


echo "############################## db back $db  end time is   $(date +%F_%T) ##############################" >> /backdb.log
sleep 2;
        echo "" >> /backdb.log
        echo "" >> /backdb.log
    done

sleep 5

find / -name "*.sql.gz" -type f -mtime +45  | xargs rm -rf
[iyunv@ ~ ]#

3、命令说明:
-q, --quick   Don't buffer query, dump directly to stdout.不要缓存查询,直接转储到stdout。
--single-transaction
                      Creates a consistent snapshot by dumping all tables in a
                      single transaction. Works ONLY for tables stored in
                      storage engines which support multiversioning (currently
                      only InnoDB does); the dump is NOT guaranteed to be
                      consistent for other storage engines. While a
                      --single-transaction dump is in process, to ensure a
                      valid dump file (correct table contents and binary log
                      position), no other connection should use the following
                      statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
                      TRUNCATE TABLE, as consistent snapshot is not isolated
                      from them. Option automatically turns off --lock-tables.
                      通过将所有表倾销到一个统一的快照中,创建一个一致的快照
                      单笔交易。只用于存储在
                      存储引擎支持多版本(目前
                      只有InnoDB也);垃圾不能保证
                      其他存储引擎的一致性。而
                      -单交易转储在过程中,以确保
                      有效的转储文件(正确的表内容和二进制日志
                      位置),没有其他连接应使用以下
                      语句:更改表、下拉表、重命名表,
                      TRUNCATETABLE,一致的快照不是孤立的
                      从他们。选项自动关闭-锁定表。
-R, --routines      Dump stored routines (functions and procedures).
                    转储存储的例程(功能和程序)。
-E, --events        Dump events. 倾倒事件。
--triggers          Dump triggers for each dumped table.转储表的转储触发器。
--default-character-set=name Set the default character set.设置默认字符集。
-B, --databases     Dump several databases. Note the difference in usage; in
                      this case no tables are given. All name arguments are
                      regarded as database names. 'USE db_name;' will be
                      included in the output.
                    转储几个数据库。注意使用中的差异;在
                    这种情况下没有表。所有名称参数
                    视为数据库名称。”使用db_name;将
                    包括在输出
--master-data[=#]   This causes the binary log position and filename to be
                      appended to the output. If equal to 1, will print it as a
                      CHANGE MASTER command; if equal to 2, that command will
                      be prefixed with a comment symbol. This option will turn
                      --lock-all-tables on, unless --single-transaction is
                      specified too (in which case a global read lock is only
                      taken a short time at the beginning of the dump; don't
                      forget to read about --single-transaction below). In all
                      cases, any action on logs will happen at the exact moment
                      of the dump. Option automatically turns --lock-tables
                      off.
                    这将导致二进制日志位置和文件名
                    追加到输出。如果等于1,将打印它作为一个
                    更改主命令;如果等于2,该命令将
                    带有一个注释符号。此选项将打开
                    -锁定所有表,除非-单交易
                    指定的(在这种情况下,一个全局读锁是唯一的
                    在转储开始的时间很短;不要
                    忘记阅读-下面的单笔交易。总共
                    案件,任何对日志的行动将发生在精确的时刻
                    的转储。选项自动打开锁定表
                    关闭。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-302126-1-1.html 上篇帖子: MHA使用过程中的问题收集 下篇帖子: MySQL高可用MHA部署 (一主二从)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表