PostgreSQL 17 : バックアップ/リストア2025/04/22 |
PostgreSQL のデータベースを バックアップ/リストア する際は付属のツールで実行可能です。 |
|
[1] | データベースのバックアップです。 |
# [--format=*] で指定可能な形式
# p = plain (SQL)
# c = custom (圧縮形式)
# t = tar
# d = directory
# [ubuntu] ユーザーが自身が所有する [testdb] データベースをバックアップ
ubuntu@www:~$ pg_dump -U ubuntu --format=t -d testdb > pg_testdb.tar ubuntu@www:~$ total 12 -rw-rw-r-- 1 ubuntu ubuntu 6656 Apr 22 05:40 pg_testdb.tar drwxr-xr-x 2 ubuntu ubuntu 4096 Apr 22 03:32 public_html # 管理ユーザー [postgres] で全データベースをバックアップ postgres@www:~$ mkdir ~/backups postgres@www:~$ pg_dumpall -f ~/backups/pg_DB_all.sql postgres@www:~$ ls -l ~/backups total 4 -rw-rw-r-- 1 postgres postgres 3465 Apr 22 05:41 pg_DB_all.sql |
[2] | バックアップファイルからのデータベースのリストアです。 |
# [ubuntu] ユーザーがバックアップファイルから [testdb] データベースをリストア ubuntu@www:~$ pg_restore -U ubuntu -d testdb pg_testdb.tar
# 管理ユーザー [postgres] でバックアップファイルから全データベースをリストア # バックアップファイルが SQL 形式の場合は [psql] で実行する postgres@www:~$ psql -f ~/backups/pg_DB_all.sql |
Sponsored Link |