备份数据::##单数据库:三种格式备份:pg_dump
-bash-4.2$ history |grep pg_dump
13 2023-11-22 15:18:17 postgres pg_dump mydb >mydb.bak
21 2023-11-22 15:20:03 postgres pg_dump mydb >mydb.bak
25 2023-11-22 15:20:20 postgres pg_dump mydb >mydb.tar
33 2023-11-22 15:21:08 postgres pg_dump mydb >mydb.sql
37 2023-11-22 15:21:39 postgres history |grep pg_dump
-f 指定备份的路径:
-bash-4.2$ pg_dump -f /tmp/mydb.sql mydb
-bash-4.2$ ls /tmp
mydb.sql vmware-root_701-3979708482 yum_save_tx.2023-11-21.15-54.Qfy3Xo.yumtx
vmware-root_677-3980363868 yum_save_tx.2023-11-21.15-52.3C3imO.yumtx
测试被删除:
所有库: pg_dumpall备份
45 2023-11-22 15:35:18 postgres pg_dumpall >postall.sql
46 2023-11-22 15:35:26 postgres du -sh postall.sql
47 2023-11-22 15:35:31 postgres cat postall.sql
48 2023-11-22 15:35:39 postgres history
恢复数据:
-bash-4.2$ psql -f postall.sql postgres