pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息。

看起来好像是模仿oracle的RMAN工具。

 pg_rman特点:

  • 使用简单.一个命令即可完成备份和恢复.
  • 支持在线全备,增量备份,归档备份.
  • 支持备份压缩.通过gzip工具实现页内压缩.
  • 自动备份维护.自动删除过期的WAL备份文件.
  • 支持备份验证.
  • 恢复期间无事务丢失.支持基于PITR的配置文件生成器.
1. 安装过程
   包:postgresql95-libs-9.5.2-1PGDG.rhel6.x86_64.rpm
--下载pg_rman,注意与其对应的数据库版本 下载地址:https://github.com/ossc-db/pg_rman/releases

包:pg_rman-1.3.2-1.pg95.rhel6.x86_64.rpm

[root@sdserver40_210 software]# rpm -ivh postgresql95-libs--1PGDG.rhel6.x86_64.rpm
warning: postgresql95-libs--1PGDG.rhel6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
Preparing...                ########################################### [%]
   :postgresql95-libs      ########################################### [%]
[root@sdserver40_210 software]# rpm -ivh pg_rman--.pg95.rhel6.x86_64.rpm
Preparing...                ########################################### [%]
   :pg_rman                ########################################### [%]

2. 配置环境变量

  pg_rman 默认是安装在/usr目录下面;注意同时pg_rman需要一个备份目录
export PG_RMAN=/usr/pgsql-9.5
export PATH=$PATH:$HOME/bin:/opt/pgsql95/bin:$PG_RMAN/bin
export BACKUP_PATH=/data/pg_rman      
                                     

3.初始化备份目录

[postgres@sdserver40_210 ~]$ pg_rman init -B /data/pg_rman
INFO: ARCLOG_PATH is set to '/home/postgres/archive'
INFO: SRVLOG_PATH is set to '/data/pgdata/pg_log'
4.备份
[postgres@sdserver40_210 ~]$ pg_rman backup --backup-mode=full --progress
INFO: copying database files
Processed  of  files, skipped
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived
INFO: copying archived WAL files
Processed  of  files, skipped
INFO: backup complete
HINT: Please execute 'pg_rman validate' to verify the files are correctly copied.

--pg_rman 的备份必须都是经过验证过的,否则不能进行恢复和增量备份

 Backups without validation cannot be used forrestoreand incremental backup--执行完备份要执行一次validate,因为备份后的状态是done,还不能进行恢复
[postgres@sdserver40_210 ~]$ pg_rman show

==========================================================
 StartTime           Mode  Duration    Size   TLI  Status
==========================================================
-- ::  FULL        0m   343MB       DONE
[postgres@sdserver40_210 ~]$ pg_rman validate
INFO: validate: "2016-05-31 16:36:45" backup and archive log files by CRC
INFO: backup "2016-05-31 16:36:45" is valid
[postgres@sdserver40_210 ~]$ pg_rman show
==========================================================
 StartTime           Mode  Duration    Size   TLI  Status
==========================================================
-- ::  FULL        0m   343MB       OK
5. 模拟恢复
[postgres@sdserver40_210 ~]$ ll
total
drwxrwxr-x  postgres postgres  May  : archive
drwxrwxr-x  postgres postgres  May  : backup
drwx------  postgres postgres  May  : data
drwxrwxr-x  postgres postgres  May  : log
-rw-rw-r--  postgres postgres    May  : out_file
-rw-rw-r--  postgres postgres   May  : out.txt
drwxrwxr-x  postgres postgres  May  : scripts
-rw-r--r--  postgres postgres    May  : test.sql
[postgres@sdserver40_210 ~]$ rm -rf data
[postgres@sdserver40_210 ~]$ ll
total
drwxrwxr-x  postgres postgres  May  : archive
drwxrwxr-x  postgres postgres  May  : backup
drwxrwxr-x  postgres postgres  May  : log
-rw-rw-r--  postgres postgres    May  : out_file
-rw-rw-r--  postgres postgres   May  : out.txt
drwxrwxr-x  postgres postgres  May  : scripts
-rw-r--r--  postgres postgres    May  : test.sql
[postgres@sdserver40_210 ~]$ pg_stop
waiting for server to shut down.... done
server stopped
[postgres@sdserver40_210 ~]$ pg_rman restore --recovery-target-time "2016-05-31 17:30:00"
INFO: the recovery target timeline ID is not given
INFO: use timeline ID of current database cluster
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: "2016-05-31 16:36:45"
INFO: copying online WAL files and server log files
INFO: clearing restore destination
INFO: validate: "2016-05-31 16:36:45" backup and archive log files by SIZE
INFO: backup "2016-05-31 16:36:45" is valid
INFO: restoring database files from the full mode backup "2016-05-31 16:36:45"
INFO: searching incremental backup to be restored
INFO: searching backup which contained archived WAL files to be restored
INFO: backup "2016-05-31 16:36:45" is valid
INFO: restoring WAL files from backup "2016-05-31 16:36:45"
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.
[postgres@sdserver40_210 ~]$ pg_start
server starting
[postgres@sdserver40_210 ~]$ psql mydb lottu
psql ()
Type "help" for help.

mydb=> \d
       List of relations
 Schema | Name | Type  | Owner
--------+------+-------+-------
 public | test | table | lottu
( row)

mydb=> select * from test;
  id  |  name
------+--------
  | lottu
  | rax
  | xuan
  | li0924
( rows)

mydb=> \q
[postgres@sdserver40_210 ~]$ ll
total
drwxrwxr-x  postgres postgres  May  : archive
drwxrwxr-x  postgres postgres  May  : backup
drwx------  postgres postgres  May  : data
drwxrwxr-x  postgres postgres  May  : log
-rw-rw-r--  postgres postgres    May  : out_file
-rw-rw-r--  postgres postgres   May  : out.txt
drwxrwxr-x  postgres postgres  May  : scripts
-rw-r--r--  postgres postgres    May  : test.sql

【参考文献】

 

POSTGRESQL9.5之pg_rman工具的更多相关文章

  1. PostgreSQL配置优化

    硬件和系统配置 操作系统 Ubuntu13.04 系统位数 64 CPU Intel(R) Core(TM)2 Duo CPU 内存 4G 硬盘 Seagate ST2000DM001-1CH164 ...

  2. windows下源码安装调试postgresql

    环境:windows 10 postgresql版本:postgresql-9.6.5 使用工具:vs2017社区版 辅助工具:perl.diff.flex.bison 相关工具下载地址: perl下 ...

  3. PostgreSQL 优势,MySQL 数据库自身的特性并不十分丰富,触发器和存储过程的支持较弱,Greenplum、AWS 的 Redshift 等都是基于 PostgreSQL 开发的

    PostgreSQL 优势 2016-10-20 21:36 686人阅读 评论(0) 收藏 举报  分类: MYSQL数据库(5)  PostgreSQL 是一个自由的对象-关系数据库服务器(数据库 ...

  4. 调试postgresql9.5.2最新源码

    最近在考量数据库的选型,考虑后期把数据切换到postgresql ,postgresql源码用c实现,代码很精炼完美,值得学习下 首先去pgsql官网下载最新的源码 ,然后还需要perl,bison ...

  5. 基于数据库的自动化生成工具,自动生成JavaBean、自动生成数据库文档等(v4.1.2版)

            目录:            第1版:http://blog.csdn.net/vipbooks/article/details/51912143            第2版:htt ...

  6. 使用pg_upgrade工具为PostgreSQL进行版本升级

    公司的测试环境和生产环境都是9.2.4版本,而开发环境是9.0.18版本. PS: 不知道公司里的其它同事,是如何做数据库迁移的,利用第三方可视化工具备份数据库,然后恢复到其它高版本的环境?反正我没成 ...

  7. linux下Postgresql-9.2安装及数据库的创建过程

    公司写部署手册需要,现总结一些linux下postgresql的安装及数据库创建的详细步骤吧! 1.1.1  软件安装   1.设置用户组和用户级别 Postgresql不能以root身份运行,要以其 ...

  8. PostgreSQL 使用PG_Rman进行物理备份

    背景 在Oracle下我们可以使用rman进行物理备份,支持数据库的全量.增量.归档的备份模式而PostgreSQL作为开源数据库,近些时间来也一直向商业版数据库看齐,也推出了开源功工具pg_rman ...

  9. win7 编译postgresql9.6.8

    一.环境 windows7 postgresql9.6.8 vs2010 perl5.24.3 二.编译安装 1.安装perl,安装到C:\Perl64路径下,安装完成后设置环境变量PATH和Perl ...

随机推荐

  1. jsp上传excel文件并导入数据库

    1,excel文件的上传 需要借助jar包:commons-fileupload-1.2.1.jar以及commons-io-1.3.2.jar 前端的html文件 <form id=" ...

  2. ClassLoader,Thread.currentThread().setContextClassLoader,tomcat的ClassLoader

    实际上,在Java应用中所有程序都运行在线程里,如果在程序中没有手工设置过ClassLoader,对于一般的java类如下两种方法获得的ClassLoader通常都是同一个 this.getClass ...

  3. Singlton设计模式

    单例定义: 确保一个类只有一个实例,并提供全局访问点. 适用场景: 1.) 当系统中某个类必须仅有一个实例对象,同时访问该系统的所有访问者必须访问同一个实例对象时,且该对象实例自身占用资源又不大时. ...

  4. PostgreSQL/bin

    pg_receivexlog pg_receivexlog—以流的方式从一个PostgreSQL集簇得到事务日志 pg_receivexlog被用来从一个运行着的PostgreSQL集簇以流的方式得到 ...

  5. G面经prepare: Reorder String to make duplicates not consecutive

    字符串重新排列,让里面不能有相同字母在一起.比如aaabbb非法的,要让它变成ababab.给一种即可 Greedy: 跟FB面经Prepare task Schedule II很像,记录每个char ...

  6. PHP判断手机号码是否合法

    <html> <head> <script language="JavaScript"> function checkMobile(input) ...

  7. C#: 数据绑定

    数据绑定是分离UI和后端主逻辑程序的一种好的办法.这里总结下TextBox, Label, ComboBox, ListBox, DataGridView的数据绑定 数据绑定都是通过DB来和UI控件的 ...

  8. android studio不能创建android项目,或者不能识别android项目的解决方法

    1.先点击file->close project回到android studio 欢迎界面,然后按如下图步骤添加相关的plugin就行了,然后重启. 2.如图 3. 4.

  9. JSon_零基础_003_将Map集合对象转换为JSon格式的对象字符串,返回给界面

    将Map集合对象转换为JSon格式的对象字符串,返回给界面 需导入的jar包: 编写servlet: package com.west.webcourse.servlet; import java.i ...

  10. 夺命雷公狗---Thinkphp----9之中间层的创建,防止跨目录访问

    我们创建一个CommonController.class.php的中间层,让后让别的控制器都直接继承CommonController这个控制器即可决解跨目录访问的问题, <?php namesp ...