postgresql使用pg_rman备份恢复
admin
2023-02-09 03:40:02
0

os:centos 7.5
postgresql: 10.0
1.软件下载:
https://github.com/ossc-db/pg_rman/releases/pg_rman-1.3.7-1.pg10.rhel7.x86_64.rpm

2.安装pg_rman:
[root@my-mm ~]# yum localinstall pg_rman-1.3.7-1.pg10.rhel7.x86_64.rpm
Loaded plugins: fastestmirror
Examining pg_rman-1.3.7-1.pg10.rhel7.x86_64.rpm: pg_rman-1.3.7-1.pg10.rhel7.x86_64
Marking pg_rman-1.3.7-1.pg10.rhel7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pg_rman.x86_64 0:1.3.7-1.pg10.rhel7 will be installed
--> Processing Dependency: postgresql10-libs for package: pg_rman-1.3.7-1.pg10.rhel7.x86_64
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.ustc.edu.cn
 * extras: centos.ustc.edu.cn
 * updates: mirrors.cn99.com
--> Finished Dependency Resolution
Error: Package: pg_rman-1.3.7-1.pg10.rhel7.x86_64 (/pg_rman-1.3.7-1.pg10.rhel7.x86_64)
           Requires: postgresql10-libs
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

安装依赖包库,再次安装::
rpm -ivh https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7.5-x86_64/pgdg-centos10-10-2.noarch.rpm
yum localinstall pg_rman-1.3.7-1.pg10.rhel7.x86_64.rpm
安装后的pg_rman 路径:
/usr/pgsql-10/bin/pg_rman

3.配置pg_rman初始化备份目录:
cd /pgdata/10/backup
/usr/pgsql-10/bin/pg_rman init -B /pgdata/10/backup/
INFO: ARCLOG_PATH is set to '/pgdata/10/archive_wal'
INFO: SRVLOG_PATH is set to '/pgdata/10/log'


4.添加用户环境变量:

su - postgres

vi ~/.bash_profile

export ARCLOG_PATH=/pgdata/10/archive_wal
export SRVLOG_PATH=/pgdata/10/log
export BACKUP_PATH=/pgdata/10/backup

5.pg_rman备份脚本:
vim /pgdata/10/script/pg_rmanbackup.sh
#!/bin/bash
source ~/.bash_profile
export ARCLOG_PATH='/pgdata/10/archive_wal'
export SRVLOG_PATH='/pgdata/10/log'
export BACKUP_PATH='/pgdata/10/backup'

/usr/pgsql-10/bin/pg_rman backup --backup-mode=full --progress -Z --keep-data-days=7 --keep-arclog-days=7 ;
/usr/pgsql-10/bin/pg_rman validate;

6.执行备份,可以添加到定时任务,下面为手动执行:
[postgres@postgres]$ chmod +x pg_rmanbackup.sh
[postgres@postgres]$ ./pg_rmanbackup.sh
INFO: copying database files
Processed 985 of 985 files, skipped 0
INFO: copying archived WAL files
Processed 4 of 4 files, skipped 0
INFO: backup complete
INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
INFO: start deleting old archived WAL files from ARCLOG_PATH (keep days = 7)
INFO: the threshold timestamp calculated by keep days is "2018-12-05 00:00:00"
INFO: start deleting old backup (keep after = 2018-12-05 00:00:00)
INFO: does not include the backup just taken
INFO: validate: "2018-12-12 03:28:38" backup and archive log files by CRC
INFO: backup "2018-12-12 03:28:38" is valid

确认:
[postgres@postgres]$ pg_rman show -B /pgdata/10/backup/
=====================================================================
 StartTime           EndTime              Mode    Size   TLI  Status
=====================================================================
2018-12-12 03:28:38  2018-12-12 03:28:46  FULL  5184kB     1  OK

6.pg_rman使用帮助:
pg_rman --help


7.恢复:
删除数据库:
rm -rf /pgdata/10/data/*
查看备份信息:
pg_rman show

=====================================================================
 StartTime           EndTime              Mode    Size   TLI  Status
=====================================================================
2018-12-12 03:28:38  2018-12-12 03:28:46  FULL  5184kB     1  OK

pg_rman  restore -D /pgdata/10/data/ --recovery-target-time='2018-12-12 10:00:00'
[postgres@postgres]$ pg_rman  restore -D /pgdata/10/data/ --recovery-target-time='2018-12-12 10:00:00' -B /pgdata/10/backup/
WARNING: pg_controldata file "/pgdata/10/data//global/pg_control" does not exist
INFO: the recovery target timeline ID is not given
INFO: use timeline ID of latest full backup as recovery target: 1
INFO: calculating timeline branches to be used to recovery target point
INFO: searching latest full backup which can be used as restore start point
INFO: found the full backup can be used as base in recovery: "2018-12-12 03:28:38"
INFO: copying online WAL files and server log files
INFO: clearing restore destination
INFO: validate: "2018-12-12 03:28:38" backup and archive log files by SIZE
INFO: backup "2018-12-12 03:28:38" is valid
INFO: restoring database files from the full mode backup "2018-12-12 03:28:38"
INFO: searching incremental backup to be restored
INFO: searching backup which contained archived WAL files to be restored
INFO: backup "2018-12-12 03:28:38" is valid
INFO: restoring WAL files from backup "2018-12-12 03:28:38"
INFO: restoring online WAL files and server log files
INFO: generating recovery.conf
INFO: restore complete
HINT: Recovery will start automatically when the PostgreSQL server is started.

启动数据库确认数据:
pg_ctl start

相关内容

热门资讯

终于明白“七千在线.有挂吗?”... 有 亲,根据资深记者爆料七千在线是可以开挂的,确实有挂(咨询软件无需打开...
玩家攻略科普“新卡农牛牛.真的... 网上科普关于“新卡农牛牛有没有挂”话题很是火热,小编也是针对新卡农牛牛作*弊开挂的方法以及开挂对应的...
终于了解“玄龙牛牛.开挂器?”... 家人们!今天小编来为大家解答玄龙牛牛透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买很...
终于了解“传送屋激k.有没有挂... 家人们!今天小编来为大家解答传送屋激k透视挂怎么安装这个问题咨询软件客服徽9752949的挂在哪里买...
今日重磅消息“丽水都莱.辅助器... 今日重磅消息“丽水都莱.辅助器?”太坑了原来有挂您好,丽水都莱这个游戏其实有挂的,确实是有挂的,需要...
最新引进“沈阳老友麻将.有挂吗... 最新引进“沈阳老友麻将.有挂吗?”其实是有挂您好,沈阳老友麻将这个游戏其实有挂的,确实是有挂的,需要...
【第一资讯】“天天微友炸金花.... 您好:天天微友炸金花这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这...
玩家攻略科普“聚友.怎么装挂?... 您好:聚友这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这款游戏中打...
今日重大通报“老友十三水.有挂... 家人们!今天小编来为大家解答老友十三水透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里买...
台陆委会发布所谓“澳门移交26... 【环球网报道】12月24日上午,国台办举行例行新闻发布会,发言人彭庆恩就近期两岸热点问题回答记者提问...