zoukankan      html  css  js  c++  java
  • PG-pg_rman物理备份工具

    g_rman 物理备份

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

    pg_rman特点

    • 使用简单一个命令即可完成备份和恢复
    • 支持在线全备,增量备份,归档备份
    • 支持备份压缩.通过gzip工具实现页内压缩
    • 自动备份维护.自动删除过期的WAL备份文件
    • 支持备份验证
    • 恢复期间无事务丢失.支持基于PITR的配置文件生成器

    下载地址

    软件安装

    wget https://github.com/ossc-db/pg_rman/releases/download/V1.3.13/pg_rman-1.3.13-pg12.tar.gz 
    
    tar -xf pg_rman-1.3.13-pg12.tar.gz
    cd pg_rman-1.3.13-pg12
    yum -y install zlib-devel
    make
    make install
    

    image-20210923101938147

    pg_rman的用法(pg_rman --help)

    pg_rman manage backup/recovery of PostgreSQL database.
    
    Usage:
      pg_rman OPTION init
      pg_rman OPTION backup
      pg_rman OPTION restore
      pg_rman OPTION show [DATE]
      pg_rman OPTION show detail [DATE]
      pg_rman OPTION validate [DATE]
      pg_rman OPTION delete DATE
      pg_rman OPTION purge
    
    Common Options:
      -D, --pgdata=PATH         location of the database storage area
      -A, --arclog-path=PATH    location of archive WAL storage area
      -S, --srvlog-path=PATH    location of server log storage area
      -B, --backup-path=PATH    location of the backup storage area
      -c, --check               show what would have been done
      -v, --verbose             show what detail messages
      -P, --progress            show progress of processed files
    
    Backup options:
      -b, --backup-mode=MODE    full, incremental, or archive
      -s, --with-serverlog      also backup server log files
      -Z, --compress-data       compress data backup with zlib
      -C, --smooth-checkpoint   do smooth checkpoint before backup
      -F, --full-backup-on-error   switch to full backup mode
                                   if pg_rman cannot find validate full backup
                                   on current timeline
          NOTE: this option is only used in --backup-mode=incremental or archive.
      --keep-data-generations=NUM keep NUM generations of full data backup
      --keep-data-days=NUM        keep enough data backup to recover to N days ago
      --keep-arclog-files=NUM   keep NUM of archived WAL
      --keep-arclog-days=DAY    keep archived WAL modified in DAY days
      --keep-srvlog-files=NUM   keep NUM of serverlogs
      --keep-srvlog-days=DAY    keep serverlog modified in DAY days
      --standby-host=HOSTNAME   standby host when taking backup from standby
      --standby-port=PORT       standby port when taking backup from standby
    
    Restore options:
      --recovery-target-time    time stamp up to which recovery will proceed
      --recovery-target-xid     transaction ID up to which recovery will proceed
      --recovery-target-inclusive whether we stop just after the recovery target
      --recovery-target-timeline  recovering into a particular timeline
      --hard-copy                 copying archivelog not symbolic link
    
    Catalog options:
      -a, --show-all            show deleted backup too
    
    Delete options:
      -f, --force               forcibly delete backup older than given DATE
    
    Connection options:
      -d, --dbname=DBNAME       database to connect
      -h, --host=HOSTNAME       database server host or socket directory
      -p, --port=PORT           database server port
      -U, --username=USERNAME   user name to connect as
      -w, --no-password         never prompt for password
      -W, --password            force password prompt
    
    Generic options:
      -q, --quiet               don't show any INFO or DEBUG messages
      --debug                   show DEBUG messages
      --help                    show this help, then exit
      --version                 output version information, then exit
    

    备份操作

    全量备份

    [postgres@progs pg_rman]$ pg_rman backup --backup-mode=full --backup-path=/ups/data/pgdata/12/backups/pg_rman
    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.
    [postgres@progs pg_rman]$
    

    增量备份

    pg_rman backup --backup-mode=incremental --backup-path=/ups/data/pgdata/12/backups/pg_rman
    

    image-20210923105803474

    备份集校验

    # 每次备份完,必须要做一次校验,否则备份集不可用用来恢复,增量备份时也不会用它来做增量比较
    export BACKUP_PATH='/ups/data/pgdata/12/backups/pg_rman' && pg_rman validate
    pg_rman validate --backup-path=/ups/data/pgdata/12/backups/pg_rman
    

    image-20210923104912916

    查看备份集

    pg_rman show
    

    image-20210923105030075

    删除备份集

    删除指定时间的备份集
    # 从catalog删除指定时间的备份集
    ## 例如:只需要能恢复到2021-09-23 11:00:00,在这个时间点以前的不需要用来恢复到这个时间点的备份全删掉
    pg_rman delete '2021-09-23 11:00:00'
    

    image-20210923110441694

    根据备份策略来删除备份集
    # 在备份时,指定备份策略
    pg_rman backup --backup-mode=incremental --keep-data-generations=2 --keep-data-days=10 --keep-data-generations=2 
    

    image-20210923111312408

    清除备份集

    它不是删除备份集中物理文件,仅删除catalog中的备份条目

    pg_rman purge
    

    image-20210923111848275

    恢复操作

    恢复操作选项

    Restore options:
      --recovery-target-time    time stamp up to which recovery will proceed
      --recovery-target-xid     transaction ID up to which recovery will proceed
      --recovery-target-inclusive whether we stop just after the recovery target
      --recovery-target-timeline  recovering into a particular timeline
      --recovery-target-action    action the server should take once the recovery target is reached
      --hard-copy                 copying archivelog not symbolic link
    

    使用最新全备恢复到$PGDATA目录

    [postgres@progs pg_rman]$ export PGDATA=/tmp/pg_recov
    [postgres@progs pg_rman]$ pg_rman restore
    

    image-20210923113259015

  • 相关阅读:
    i++ ++i i=i+1 和i+=1
    cmd命令行 端口
    WAS 查看服务状态
    Linux 拷贝
    jar 压缩 解压 war包
    数据结构
    jar包生成exe可执行程序
    03-vant的一些事
    01-watch原理/computed原理
    05-问题集合
  • 原文地址:https://www.cnblogs.com/binliubiao/p/15324778.html
Copyright © 2011-2022 走看看