开发者社区 > PolarDB开源 > PolarDB 分布式版 > 正文

如何使用pg_rman做备份?

如何使用pg_rman做备份?

展开
收起
开发者小助手_LS 2022-07-15 16:32:47 7679 0
2 条回答
写回答
取消 提交回答
  • 本人csdn 博客地址https://liuyunshengsir.blog.csdn.net/ 推荐的chatgpt地址:http://124.220.104.235/web/chatgpt

    pg_rman是一款专门为postgresql设计的在线备份恢复的工具。其支持在线和基于时间点备份方式,还可以通过创建backup catalog来维护DB cluster备份信息。 - 使用简单.一个命令即可完成备份和恢复. - 支持在线全备,增量备份,归档备份. - 支持备份压缩.通过gzip工具实现页内压缩. - 自动备份维护.自动删除过期的WAL备份文件. - 支持备份验证. - 恢复期间无事务丢失.支持基于PITR的配置文件生成器.

    1.下载安装

    找到对应版本下载,默认安装到路径/usr/pgsql-13/bin

    https://github.com/ossc-db/pg_rman/releases
    wget https://github.com/ossc-db/pg_rman/releases/download/V1.3.14/pg_rman-1.3.14-1.pg13.rhel8.x86_64.rpm
    
    yum install pg_rman-1.3.14-1.pg13.rhel8.x86_64.rpm
    

    2.PostgreSQL configuration

    sed -ir "s/#*max_wal_senders.*/max_wal_senders = 10/" postgresql.conf
    sed -ir "s/#*max_replication_slots.*/max_replication_slots= 10/" postgresql.conf
    sed -ir "s/#*hot_standby .*/hot_standby = on/" postgresql.conf
    sed -ir "s/#*wal_level.*/wal_level = replica/" postgresql.conf
    sed -ir "s/#*archive_mode.*/archive_mode = on/" postgresql.conf
    sed -ir "s/#*archive_command.*/archive_command = '\/bin\/true'/" postgresql.conf
    
    
    
    # 检查
    cat postgresql.conf | grep "max_replication_slots\|max_wal_senders\|wal_level\|archive_mode\|archive_command\|hot_standby "
    
    

    修改完重启

    systemctl restart postgresql-13
    

    3.初始化

    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data --arclog-path /lys/data/arclog init
    INFO: ARCLOG_PATH is set to '/lys/data/arclog'
    INFO: SRVLOG_PATH is set to '/var/lib/pgsql/13/data/log'
    
    

    4.全量备份

    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data --arclog-path /lys/data/arclog  backup -b full -U user001 -d db001 -h 127.0.0.1 -p 5432
    Password for user user001:
    INFO: copying database files
    INFO: copying archived WAL files
    INFO: backup complete
    INFO: Please execute 'pg_rman validate' to verify the files are correctly copied.
    
    

    5.增量备份

    增量备份前必须先验证

    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data  validate
    INFO: validate: "2022-07-28 08:04:54" backup and archive log files by CRC
    INFO: backup "2022-07-28 08:04:54" is valid
    
    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data  show
    =====================================================================
     StartTime           EndTime              Mode    Size   TLI  Status
    =====================================================================
    2022-07-28 08:05:51  2022-07-28 08:05:54  INCR      0B     1  ERROR
    2022-07-28 08:04:54  2022-07-28 08:05:00  FULL    37MB     1  OK
    
    
    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data  validate
    INFO: validate: "2022-07-28 08:08:05" backup and archive log files by CRC
    INFO: backup "2022-07-28 08:08:05" is valid
    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data  show
    =====================================================================
     StartTime           EndTime              Mode    Size   TLI  Status
    =====================================================================
    2022-07-28 08:08:05  2022-07-28 08:08:10  INCR    24kB     1  OK
    2022-07-28 08:05:51  2022-07-28 08:05:54  INCR      0B     1  ERROR
    2022-07-28 08:04:54  2022-07-28 08:05:00  FULL    37MB     1  OK
    
    
    

    6.删除备份

    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data delete "2022-07-28 08:05:51"
    INFO: delete the backup with start time: "2022-07-28 08:05:51"
    WARNING: cannot delete backup with start time "2022-07-28 08:04:54"
    DETAIL: This is the latest full backup necessary for successful recovery.
    [root@lys-mysql pg_rman]# /usr/pgsql-13/bin/pg_rman  --backup-path /lys/data/pg_rman  --pgdata /var/lib/pgsql/13/data  show
    =====================================================================
     StartTime           EndTime              Mode    Size   TLI  Status
    =====================================================================
    2022-07-28 08:08:05  2022-07-28 08:08:10  INCR    24kB     1  OK
    2022-07-28 08:04:54  2022-07-28 08:05:00  FULL    37MB     1  OK
    
    
    2022-11-22 17:15:18
    赞同 展开评论 打赏
  • image.png

    image.png

    以上内容摘自《PolarDB for Postgres SQL 》电子书,点击https://developer.aliyun.com/ebook/download/7673可下载完成版

    2022-07-18 11:16:59
    赞同 展开评论 打赏

PolarDB 分布式版 (PolarDB for Xscale,简称“PolarDB-X”) 是阿里云自主设计研发的高性能云原生分布式数据库产品,为用户提供高吞吐、大存储、低延时、易扩展和超高可用的云时代数据库服务。

相关电子书

更多
迁移 ORACLE 最佳实践 立即下载
Oracle 数据库笔记 立即下载
PolarDB-X 2.0 全局 Binlog 与备份恢复能 立即下载