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

Dockerのホスト側でデータベース復元

Last updated at Posted at 2019-10-24

環境

Docker

準備

直接パスワード入れるのはアレなので、
設定ファイル作っておく。

また、docker-compose.ymlでボリュームとか設定する。
このデータ共有されてるホスト側のパスを後ほど指定する。

シェル

doHukugen.sh
docker exec -i {コンテナID} mysql --defaults-file=db.conf {データベース名} < ../migration/datastore/{ダンプファイル名}.dump


オプションについて

オプションについては下記に詳しく書いてある。
https://hodalog.com/how-to-resolve-the-error-that-the-input-device-is-not-a-tty/

dockerコマンドの-tオプションは「TTYを割り当ててくれる」オプション。
このオプションを外すことでcronジョブが正常に実行できるようになります。
なので、tをつけると、TTYがないみたいなエラーが出るからつけない。

ついでに-iは「標準入力を開き続ける」オプションで、これもCLIでコンテナを操作するために必要なオプション。
これはもちろん必要なので今回はこのオプションだけ。

結果

このシェルスクリプトを実行してみると、指定したダンプファイルの状態にデータが戻った

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?