postgresql 10数据库备份 pg_probackup 简明教程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了postgresql 10数据库备份 pg_probackup 简明教程相关的知识,希望对你有一定的参考价值。

测试环境说明


OS:CentOS Linux release 7.3.1611 (Core) X64

PG:pg10 beta3 source install

pg_probackup: 2.0.3 source install


建立归档备份目录


[[email protected] ~]# mkdir /backupdir

[[email protected] ~]# chown postgres.postgres -R /backupdir


数据库参数配置


### - Archiving - ###

archive_mode = on              

archive_command = ‘pg_probackup archive-push -B /backupdir --instance pg10 --wal-file-path %p --wal-file-name %f‘


### default ###

max_wal_senders = 10

hot_standby = on

full_page_writes = on


初始化备份目录


[[email protected] ~]# su - postgres

[[email protected] ~]$ pg_probackup init -B /backupdir

INFO: Backup catalog ‘/backupdir‘ successfully inited


添加备份实例目录


[[email protected] ~]$ pg_probackup add-instance -B /backupdir -D /pgdata10/ --instance pg10

INFO: Instance ‘pg10‘ successfully inited


显示备份实例配置


[[email protected] ~]$ pg_probackup show-config -B /backupdir --instance pg10

#Backup instance info

PGDATA = /pgdata10/

system-identifier = 6460633300993501667

#Connection parameters:

PGDATABASE = postgres

#Replica parameters:

#Logging parameters:

#Retention parameters:

#Compression parameters:

compress-algorithm = none

compress-level = 6

[[email protected] ~]$ pg_probackup backup -B /backupdir -b full --instance pg10

INFO: wait for pg_stop_backup()

INFO: Backup OVKYC7 completed

[[email protected] ~]$ 


增量备份


[[email protected] ~]$ pg_probackup backup -B /backupdir -b PAGE --instance pg10

INFO: wait for LSN 0/4000028 in archived WAL segment /backupdir/wal/pg10/000000010000000000000004

INFO: wait for pg_stop_backup()

INFO: Backup OVKYME completed

[[email protected] ~]$ 


显示备份


[[email protected] ~]$ pg_probackup show -B /backupdir


BACKUP INSTANCE ‘pg10‘

===============================================================================================================================

 Instance    ID      Recovery time        Mode    WAL      Current/Parent TLI    Time    Data    Start LSN    Stop LSN   Status  

===============================================================================================================================

 pg10        OVKYME  2017-09-01 10:51:56  PAGE    ARCHIVE    1 / 0                 8s  4407kB   0/4000028    0/50000F0   OK      

 pg10        OVKYC7  2017-09-01 10:45:57  FULL    ARCHIVE    1 / 0                17s    31MB   0/2000060    0/2000198   OK      

[[email protected] ~]$ 


验证备份


[[email protected] ~]$ pg_probackup validate -B /backupdir --instance pg10

INFO: Validate backups of the instance ‘pg10‘

INFO: Validate backup OVKYME

INFO: backup validation completed successfully

INFO: Validate backup OVKYC7

INFO: backup validation completed successfully

INFO: All backups are valid

[[email protected] ~]$


恢复备份


[[email protected] pgdata10]$ pg_probackup restore -B /backupdir --instance pg10 -D /pgdata10/

INFO: backup validation completed successfully




配置保存期限


[[email protected] ~]$ pg_probackup set-config -B /backupdir --instance pg10 --retention-redundancy 2 --retention-window 7

[[email protected] ~]$ pg_probackup show-config -B /backupdir --instance pg10

#Backup instance info

PGDATA = /pgdata10/

system-identifier = 6460633300993501667

#Connection parameters:

PGDATABASE = postgres

#Replica parameters:

#Logging parameters:

#Retention parameters:

retention-redundancy = 2

retention-window = 7

#Compression parameters:

compress-algorithm = none

compress-level = 6

[[email protected] ~]$ 


并行备份


full


[[email protected] ~]$ pg_probackup backup -B /backupdir --instance pg10 -b FULL -j 4

INFO: wait for pg_stop_backup()

INFO: Backup OVL360 completed

[[email protected] ~]$


incremental

[[email protected] ~]$ pg_probackup backup -B /backupdir --instance pg10 -b page  -j 6

INFO: wait for LSN 0/B000028 in archived WAL segment /backupdir/wal/pg10/00000002000000000000000B

INFO: wait for pg_stop_backup()

INFO: Backup OVL3BK completed

[[email protected] ~]$ 

[[email protected] ~]$ 

[[email protected] ~]$ pg_probackup show -B /backupdir --instance pg10 

===============================================================================================================================

 Instance    ID      Recovery time        Mode    WAL      Current/Parent TLI    Time    Data    Start LSN    Stop LSN   Status  

===============================================================================================================================

 pg10        OVL3BK  2017-09-01 12:33:24  PAGE    ARCHIVE    2 / 1                 6s  4417kB   0/B000028    0/C0000F0   OK      

 pg10        OVL360  2017-09-01 12:30:11  FULL    ARCHIVE    2 / 1                13s    31MB   0/9000060    0/9000198   OK      

 pg10        OVKYME  2017-09-01 10:51:56  PAGE    ARCHIVE    1 / 0                 8s  4407kB   0/4000028    0/50000F0   OK      

 pg10        OVKYC7  2017-09-01 10:45:57  FULL    ARCHIVE    1 / 0                17s    31MB   0/2000060    0/2000198   OK      

[[email protected] ~]$ 



restore


[[email protected] ~]$ pg_probackup restore -B /backupdir --instance pg10 -D /pgdata10/ -j 6

INFO: backup validation completed successfully

INFO: Restore of backup OVL3BK completed.

[[email protected] ~]$ pg_probackup show -B /backupdir --instance pg10 -D /pgdata10

===============================================================================================================================

 Instance    ID      Recovery time        Mode    WAL      Current/Parent TLI    Time    Data    Start LSN    Stop LSN   Status  

===============================================================================================================================

 pg10        OVL3BK  2017-09-01 12:33:24  PAGE    ARCHIVE    2 / 1                 6s  4417kB   0/B000028    0/C0000F0   OK      

 pg10        OVL360  2017-09-01 12:30:11  FULL    ARCHIVE    2 / 1                13s    31MB   0/9000060    0/9000198   OK      

 pg10        OVKYME  2017-09-01 10:51:56  PAGE    ARCHIVE    1 / 0                 8s  4407kB   0/4000028    0/50000F0   OK      

 pg10        OVKYC7  2017-09-01 10:45:57  FULL    ARCHIVE    1 / 0                17s    31MB   0/2000060    0/2000198   OK      

[[email protected] ~]$

本文出自 “yiyi” 博客,请务必保留此出处http://heyiyi.blog.51cto.com/205455/1961899

以上是关于postgresql 10数据库备份 pg_probackup 简明教程的主要内容,如果未能解决你的问题,请参考以下文章

Centos7 备份 PostgreSQL 数据脚本

Postgresql - 备份数据库并恢复不同的所有者?

PostgreSQL备份与恢复(第三章)

[完整版]Postgresql 数据库 备份以及恢复的过程

windows postgresql定时备份 无需手动输入密码

PgSQL · 源码分析 · PostgreSQL物理备份内部原理