3
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 5 years have passed since last update.

mysqldumpでdumpしながらgzip圧縮をしつつSSHで別ホストに転送する

Posted at

よく忘れて調べ直すのでメモ。というか単なる備忘録。
たぶんもっといい方法があると思うし、時と場合によって使い分けるべきかと。

ダンプ

/usr/bin/mysqldump -u[ユーザ名] -p[パスワード] --single-transaction --master-data --routines --databases [データベース名] [データベース名] [データベース名...] | gzip | ssh [転送先ホスト] 'cat > [だんぷファイル名.dump.gz]'
オプション 説明
--single-transaction ロックせずにダンプを取得するオプション
--master-data スレーブ側からダンプする際に、マスター機のポジションデータも含めるオプション
--routines  ルーチンを再作成するためのCREATE PROCEDUREおよびCREATE FUNCTION文が含まれるオプション
--databases 複数データベースを指定するオプション

gzipで圧縮しながらSSHに流し込むので、CPUをかなり食う。
ディスク領域やネットワーク帯域に余裕があるのなら、gzip圧縮せずに流したほうが速いかもしれない。

gzip圧縮したダンプファイルのリストア

zcat [だんぷファイル名.dump.gz] | mysql -u[ユーザ名] -p[パスワード]

毎回みてる参考ページ

mysqldump の結果をそのまま圧縮したり転送したりするコマンド例
http://bashalog.c-brains.jp/10/09/30-183733.php

3
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
3
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?