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 --
阅读(4000) | 评论(0) | 转发(0) |