简体   繁体   English

忽略mysqldump中的表?

[英]Ignoring table in mysqldump?

Hi I'm doing a database copy and paste from a master to a slave. 嗨,我正在从主数据库copy and paste数据库copy and paste到从数据库。 However there is a table on the slave that I don't want to be overwritten by the master. 但是,从属服务器上有一个我不想被主服务器覆盖的表。

I have been trying out the following bash script which is ran via cron job - but it keeps overwriting the slave table I want to ignore. 我一直在尝试通过cron作业运行的以下bash脚本-但它会不断覆盖我想忽略的从属表。 What am I doing wrong? 我究竟做错了什么?

#!/bin/bash

#Database login credentials - need to be changed accordingly
dbHost="localhost"

#Master (Staging)
dbMastUser="admin_site"
dbMastName="admin_site_pineapple_master"

#Slave (Live)
dbSlavUser="admin_sync"
dbSlavName="admin_site_pineapple_slave"

dbPass="ExamplePassword"


EXCLUDED_TABLES=(
forms-responses
)

IGNORED_TABLES=''
for TABLE in "${EXCLUDED_TABLES[@]}"
do :
   IGNORED_TABLES+=" --ignore-table=${dbMastName}.${TABLE}"
done

#Update the database from the Master to the Slave
mysqldump -h ${dbHost} -u ${dbMastUser} -p${dbPass} ${dbMastName} ${IGNORED_TABLES} | mysql -h ${dbHost} -u ${dbSlavUser} -p${dbPass} ${dbSlavName}

For ignoring tables you must use this syntax 要忽略表,必须使用以下语法

mysqldump -h {hostname} -u {username} -p{password} --ignore-table test.votes test > E:/db_backups/test_1480080906.sql

general syntax 一般语法

mysqldump -h {hostname} -u {username} -p{password} --ignore-table dbname.tbl_name db_name > E:/db_backups/test_1480080906.sql

Note : we need to set the options to ignore some tables 注意:我们需要设置选项以忽略某些表

Thanks Suman W. 感谢Suman W.

/usr/local/mysql/bin/mysqldump -uroot -p{pwd} --skip-lock-tables  --databases f6dms $(mysql -uroot -p{pwd} -Df6dms -Bse "show tables like 'tm_monitor_avg_price_%'"|awk '{print "--ignore-table=f6dms."$1}'|xargs)| gzip > /data/backup/database_f6dms_`date '+%m-%d-%Y'`.sql.gz;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM