■ はじめに
* バックアップ/リストアについて、困ったら、以下の公式を読みといいかも。https://www.postgresql.jp/document/9.4/html/backup.html
* また、注意事項も含めて、以下を一読しておくといいかも。http://www.atmarkit.co.jp/ait/articles/0810/24/news135_2.html
■ データのバックアップ
pg_dump
構文pg_dump.exe -b -Fc -U 【ユーザ名】 【DB名】 > 【出力ダンプ・ファイル名】 # -b : ラージオブジェクトをダンプに含める # -Fc : カスタム形式でのダンプ(-Ftとするとtar形式)サンプル (Windowsの場合)
pg_dump.exe -b -Fc -U postgres sampledb > c:\temp\sample.backup.dump参考文献
* 仕様http://www.postgresql.jp/document/9.4/html/app-pgdump.html
http://wp.tech-style.info/archives/563
pg_dumpall
* 全データベースのバックアップをとるサンプル (Linuxの場合)
# postgresユーザーにスイッチ sudo -u postgres -i postgres@debian:~$ pg_dumpall > sample.sql【注意】 -Fオプションは使えない
* 復元する際に、pg_restoreを使えない ~~~~~~ pg_restore: [アーカイバ] 入力ファイルがテキスト形式のダンプのようです。psqlを使用してください ~~~~~~
■ データの復元(リストア)
pg_restore
構文pg_restore.exe -U 【ユーザ名】 -c -Fc 【入力ダンプ・ファイル名】 -d 【DB名】 # -c : データベースの作成前にテーブルなどをドロップする。 # -F : カスタム形式でのダンプ(-Ftとするとtar形式、-Fpがテキスト) # -d : データベース名を指定 # #[その他] # -v : 進捗状況を詳細表示サンプル
pg_restore.exe -U postgres -c -Fc c:\temp\sample.backup.dump参考文献
* 仕様https://www.postgresql.jp/document/9.4/html/app-pgrestore.html
http://www.desknets.com/neo/download/doc/install/dneo_winpg92_mainte.html
関連記事
PostgreSQLのDBをエクスポート/インポートするスクリプト
https://blogs.yahoo.co.jp/dk521123/37421399.html外部プログラム/コマンドを実行するには ~ ProcessBuilder ~
* Javaでの実行を載せているhttp://blogs.yahoo.co.jp/dk521123/34842155.html