pg_basebackup 命令行参数

pg_basebackup是postgresql提供的一个方便基础备份的工具(9.1开始提供),这个工具会把整个数据库实例的数据都拷贝出来,而不只是把实例中的部分(如某个数据库或表)单独备份出来,该工具使用replication协议连接到数据库实例上,所以主数据库中的pg_hba.conf必须允许replication连接,类似如下:
local   replication     postgre                                 ident
在9.2之后支持级连复制,所以在之后的版本中,pg_basebackup也可以从另外一个standby库上做基础备份,都需注意如下几方面:
1、备份中没有备份历史文件;
2、不确保所有需要的WAL文件都备份了,如果想确保,需要加命令行参数 ”-x";
3、如果在备份过程中standby被提升为主库,则备份会失败;
4、要求主库中打开了“full_page_writes"参数,WAL文件不能被类似pg_compresslog的工具去掉full_page_writes信息。

[postgre@pg-1 backup]$ pg_basebackup --help
pg_basebackup takes a base backup of a running PostgreSQL server.

Usage:
  pg_basebackup [OPTION]...

Options controlling the output:
  -D, --pgdata=DIRECTORY receive base backup into directory
        指定把备份写到那个目录,如果这个目录或这个目录路径中的各级父目录不存在,则pg_basebackup就会自动创建这个目录,如果目录存在,但目录不为空,则会导致pg_basebackup执行失败。
  -F, --format=p|t       output format (plain (default), tar)
         指定输出格式:p原样输出,即把主数据库中的各个数据文件,配置文件、目录结构都完全一样的写到备份目录;
                                 t 把输出的备份文件打包到一个tar文件中。
  -r, --max-rate=RATE    maximum transfer rate to transfer data directory
                         (in kB/s, or use suffix "k" or "M")
  -R, --write-recovery-conf
                         write recovery.conf after backup
            生成recovery.conf文件
  -T, --tablespace-mapping=OLDDIR=NEWDIR
                         relocate tablespace in OLDDIR to NEWDIR
  -x, --xlog             include required WAL files in backup (fetch mode)
            备份时会把备份中产生的xlog文件也自动备份出来,这样才能在恢复数据库时,应用这些xlog文件把数据库推到一个一致点,然后真正打开这个备份的数据库,这个选项与 -X fetch是完全一样的。使用这个选项,需要设置“wal_keep_segments"参数,以保证在备份过程中,需要的WAL日志文件不会被覆盖。

  -X, --xlog-method=fetch|stream
                         include required WAL files with specified method
      --xlogdir=XLOGDIR  location for the transaction log directory
  -z, --gzip             compress tar output 
         使用gzip压缩,仅能能与tar输出模式配合使用。
  -Z, --compress=0-9     compress tar output with given compression level
           指定压缩级别

General options:
  -c, --checkpoint=fast|spread
                         set fast or spread checkpointing
            设置checkpoint的模式。
  -l, --label=LABEL      set backup label
            设置备份标识,
  -P, --progress         show progress information
            在备份过程中实时打印备份进度
  -v, --verbose          output verbose messages
              详细模式,使用了-P后,还会打印出正在备份的具体文件的信息。
  -V, --version          output version information, then exit
  -?, --help             show this help, then exit

Connection options:
  -d, --dbname=CONNSTR   connection string
  -h, --host=HOSTNAME    database server host or socket directory
  -p, --port=PORT        database server port number
  -s, --status-interval=INTERVAL
                         time between status packets sent to server (in seconds)
  -U, --username=NAME    connect as specified database user
  -w, --no-password      never prompt for password
  -W, --password         force password prompt (should happen automatically)

Report bugs to <pgsql-bugs@postgresql.org>.


示例:

[postgre@pg-1 pg_log]$ pg_basebackup   -D backup     -Ft  -z -R -P 
44174/44174 kB (100%), 1/1 tablespace
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived

[postgre@pg-1 pg_log]$ pg_basebackup   -D backup     -Fp    -P 
44532/44532 kB (100%), 1/1 tablespace
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived

示例中没有指定任何连接参数,所以就像psql命令中没有指定连接参数的方式一样连接到本地的数据库上。想让后续命令成功运行,一般要在pg_hba.conf上允许本地连接,如做如下类似配置:
local   replication     postgre                                 ident
走ident认证,表示需要与数据库用户 postgre存在一个对应的操作系统用户。

标识示例:
[postgre@pg-1 pg_log]$ pg_basebackup   -D backup     -Fp  -R   -P   -l postgrebackup-20150716 
44532/44532 kB (100%), 1/1 tablespace
NOTICE:  pg_stop_backup complete, all required WAL segments have been archived

[postgre@pg-1 backup]$ cat backup_label 
START WAL LOCATION: 0/13000028 (file 000000010000000000000013)
CHECKPOINT LOCATION: 0/13000060
BACKUP METHOD: streamed
BACKUP FROM: master
START TIME: 2015-07-16 16:21:49 CST
LABEL: postgrebackup-20150716


  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值