Fedora 37
Sponsored Link

PostgreSQL 14 : バックアップ/リストア2022/11/24

 
PostgreSQL のデータベースを バックアップ/リストア する際は付属のツールで実行可能です。
[1] データベースのバックアップです。
# [--format=*] で指定可能な形式
#     p = plain (SQL)
#     c = custom (圧縮形式)
#     t = tar
#     d = directory

# [fedora] ユーザーが自身が所有する [testdb] データベースをバックアップ
[fedora@www ~]$
pg_dump -U fedora --format=t -d testdb > pg_testdb.tar

[fedora@www ~]$
total 8
-rw-r--r--. 1 fedora fedora 4608 Nov 24 16:03 pg_testdb.tar


# 管理ユーザー [postgres] で全データベースをバックアップ

[postgres@www ~]$
pg_dumpall -f ~/backups/pg_DB_all.sql

[postgres@www ~]$
ll ~/backups

total 4
-rw-r--r--. 1 postgres postgres 3193 Nov 24 15:28 pg_DB_all.sql
[2] バックアップファイルからのデータベースのリストアです。
# [fedora] ユーザーがバックアップファイルから [testdb] データベースをリストア

[fedora@www ~]$
pg_restore -U fedora -d testdb pg_testdb.tar

# 管理ユーザー [postgres] でバックアップファイルから全データベースをリストア
# バックアップファイルが SQL 形式の場合は [psql] で実行する

[postgres@www ~]$
psql -f ~/backups/pg_DB_all.sql

関連コンテンツ