Debian 12 bookworm
Sponsored Link

PostgreSQL 15 : Backup and Restore2023/07/05

 
For Backup and Restore PostgreSQL Data, it's possible to run with [pg_dump] and [pg_restore].
[1] Backup Databases.
# available types for [--format=*]
#     p = plain (SQL)
#     c = custom (compression)
#     t = tar
#     d = directory

# [debian] user takes backup of [testdb]
debian@www:~$
pg_dump -U debian --format=t -d testdb > pg_testdb.tar

debian@www:~$
total 8
-rw-r--r-- 1 debian debian 6656 Jul  4 22:36 pg_testdb.tar


# admin user [postgres] takes backup of all databases

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

postgres@www:~$
ll ~/backups

total 4
-rw-r--r-- 1 postgres postgres 3656 Jul  4 22:37 pg_DB_all.sql
[2] Restore Databases.
# [debian] user restores [testdb] database from backup file

debian@www:~$
pg_restore -U debian -d testdb pg_testdb.tar

# admin user [postgres] restores all database from backup file
# if the type of backup file is SQL text, use [psql] command for restoring

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

Matched Content