0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MySQLダンプでignoreを使った同期ジョブ

Last updated at Posted at 2023-06-06

MySQLダンプでignoreを使った同期ジョブ

ignoreTableのテキストファイルにテーブル名を記載して管理することを想定したスクリプト。
あまり良い出来栄えとはいかないがとりあえず動くものを作成したので備忘録。
今後構成含めて見直していきたい。

#!/bin/bash

# テーブル一覧取得
mysql --defaults-extra-file=dbaccess.cnf --port <port> <db_name> -N -s -e 'select table_name from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA="<db_name>";' > tebleList.txt

# ダンプファイルの取得
while read line
do
    echo $line

    if ! grep -q $line ignoreTable.txt && ! grep -q $line ignoreTable2.txt; then
        mysqldump --defaults-extra-file=dbaccess.cnf --port <port> <db_name> $line > ./sql/$line.sql
    fi
done < ./tebleList.txt

# ダンプファイルのインポート
while read line
do
    echo $line

    if ! grep -q $line ignoreTable.txt && ! grep -q $line ignoreTable2.txt; then
        mysql --defaults-extra-file=dbaccess.cnf --port <port> <db_name> < ./sql/$line.sql
    fi
done < ./tebleList.txt

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?