Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2901047
  • 博文数量: 793
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 11121
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(793)

文章存档

2018年(142)

2017年(75)

2016年(48)

2015年(48)

2014年(152)

2013年(49)

2012年(157)

2011年(93)

2010年(30)

分类: Mysql/postgreSQL

2018-09-03 10:43:39

1.停掉数据库
[postgres@localhost rmanbak]$ pg_ctl stop -m immediate -D /db/pgsql/data
waiting for server to shut down.... done
server stopped

2.删除pg_data目录下的所有文件,我这里是重命名文件夹
[postgres@localhost pgsql]$ mv data bakdata
[postgres@localhost pgsql]$ mkdir data

删除原来的表空间目录
rm -rf /db/pgsql/tps_data01
rm -rf /db/pgsql/tps_data02

rman会自动恢复表空间到原来的目录
3.恢复
[postgres@localhost rmanbak]$ pg_rman restore -B /db/pgsql/rmanbak -D /db/pgsql/data
WARNING: pg_controldata file "/db/pgsql/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: 4
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-08-31 14:54:03"
INFO: copying online WAL files and server log files
INFO: clearing restore destination
INFO: validate: "2018-08-31 14:54:03" backup, archive log files and server log files by SIZE
INFO: backup "2018-08-31 14:54:03" is valid
INFO: restoring database files from the full mode backup "2018-08-31 14:54:03"
INFO: searching incremental backup to be restored
INFO: validate: "2018-08-31 15:38:24" backup, archive log files and server log files by SIZE
INFO: backup "2018-08-31 15:38:24" is valid
INFO: restoring database files from the incremental mode backup "2018-08-31 15:38:24"
INFO: validate: "2018-09-03 09:51:30" backup, archive log files and server log files by SIZE
INFO: backup "2018-09-03 09:51:30" is valid
INFO: restoring database files from the incremental mode backup "2018-09-03 09:51:30"
INFO: searching backup which contained archived WAL files to be restored
INFO: backup "2018-09-03 09:51:30" is valid
INFO: restoring WAL files from backup "2018-09-03 09:51:30"
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.

4.修改recovery.conf
pg恢复数据文件后,会在data目录下自动生成一个recovery.conf文件,该文件内容如下
[postgres@localhost data]$ more recovery.conf
# recovery.conf generated by pg_rman 1.3.6
restore_command = 'cp /db/pgsql/archlog/%f %p'
recovery_target_timeline = '9'

要想恢复并应用所有的日志文件,需要将recovery_target_timeline = '9'去掉,最后的文件内容如下:
[postgres@localhost data]$ more recovery.conf
# recovery.conf generated by pg_rman 1.3.6
restore_command = 'cp /db/pgsql/archlog/%f %p'


5.启动pg
[postgres@localhost rmanbak]$ pg_ctl -D /db/pgsql/data start
waiting for server to start....2018-09-03 10:37:49.986 CST [32290] FATAL:  data directory "/db/pgsql/data" has group or world access
2018-09-03 10:37:49.986 CST [32290] DETAIL:  Permissions should be u=rwx (0700).
 stopped waiting
pg_ctl: could not start server
Examine the log output.

解决办法:
[postgres@localhost pgsql]$ chown -R postgres:postgres ./data/
[postgres@localhost pgsql]$ chmod -R 0700 ./data


再次启动
[postgres@localhost pgsql]$ pg_ctl -D /db/pgsql/data start
waiting for server to start....2018-09-03 10:40:43.937 CST [32450] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2018-09-03 10:40:43.937 CST [32450] LOG:  listening on IPv6 address "::", port 5432
2018-09-03 10:40:43.979 CST [32450] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2018-09-03 10:40:44.084 CST [32450] LOG:  redirecting log output to logging collector process
2018-09-03 10:40:44.084 CST [32450] HINT:  Future log output will appear in directory "/db/pgsql/log".
.. done
server started




-- The End --
阅读(9) | 评论(0) | 转发(0) |
0

上一篇:pg_rman部署安装

下一篇:没有了

给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册