增量备份-创建基础备份
使用pg_basebackup 创建基础备份
[postgres@s101 /usr/pgsql-13/bin]$
pg_basebackup
设置配置文件pg_hba.conf,添加连接信息,否则会报错
[postgres@s101 /usr/pgsql-13/bin]$/usr/pgsql-13/bin/pg_basebackup -D /var/lib/pgsql/13/backups -Ft -Pv -Xf -z -Z5 -h 192.168.17.101 -U postgres -p 5432 pg_basebackup: error: FATAL: no pg_hba.conf entry for replication connection from host "192.168.17.101", user "postgres", SSL off
[root@s101 /var/lib/pgsql/13/data]#nano pg_hba.conf
# Allow replication connections from localhost, by a user with the # replication privilege. host replication postgres 192.168.17.101/32 trust
重启数据库
[root@s101 /var/lib/pgsql/13/data]#sudo systemctl restart postgresql-13
使用pg_basebackup 创建基础备份
/usr/pgsql-13/bin/pg_basebackup -D /var/lib/pgsql/13/backups -Ft -Pv -Xf -z -Z5 -h 192.168.17.101 -U postgres -p 5432 -D -F -P -v -X -z, --gzip compress tar output 使用gzip压缩,仅能能与tar输出模式配合使用
-Z, --compress=0-9 compress tar output with given compression level 指定压缩级别
参考 : https://blog.csdn.net/feixiangtianshi/article/details/49152691
[postgres@s101 /usr/pgsql-13/bin]$/usr/pgsql-13/bin/pg_basebackup -D /var/lib/pgsql/13/backups -Ft -Pv -Xf -z -Z5 -h 192.168.17.101 -U postgres -p 5432 pg_basebackup: initiating base backup, waiting for checkpoint to complete pg_basebackup: checkpoint completed pg_basebackup: write-ahead log start point: 0/D0000028 on timeline 1 935818/935818 kB (100%), 2/2 tablespaces pg_basebackup: write-ahead log end point: 0/D0000138 pg_basebackup: syncing data to disk ... pg_basebackup: renaming backup_manifest.tmp to backup_manifest pg_basebackup: base backup completed
查看备份文件
帮助文档
[root@s101 /usr/pgsql-13]#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 -F, --format=p|t output format (plain (default), 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 configuration for replication -T, --tablespace-mapping=OLDDIR=NEWDIR relocate tablespace in OLDDIR to NEWDIR --waldir=WALDIR location for the write-ahead log directory -X, --wal-method=none|fetch|stream include required WAL files with specified method -z, --gzip compress tar output -Z, --compress=0-9 compress tar output with given compression level General options: -c, --checkpoint=fast|spread set fast or spread checkpointing -C, --create-slot create replication slot -l, --label=LABEL set backup label -n, --no-clean do not clean up after errors -N, --no-sync do not wait for changes to be written safely to disk -P, --progress show progress information -S, --slot=SLOTNAME replication slot to use -v, --verbose output verbose messages -V, --version output version information, then exit --manifest-checksums=SHA{224,256,384,512}|CRC32C|NONE use algorithm for manifest checksums --manifest-force-encode hex encode all file names in manifest --no-estimate-size do not estimate backup size in server side --no-manifest suppress generation of backup manifest --no-slot prevent creation of temporary replication slot --no-verify-checksums do not verify checksums -?, --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@lists.postgresql.org>. PostgreSQL home page: <https://www.postgresql.org/>