본문으로 건너뛰기

11.5 pgBackRest

pgBackRest는 PostgreSQL의 가장 널리 쓰이는 운영급 백업 도구입니다. Crunchy Data와 커뮤니티가 유지보수하는 BSD 라이선스 오픈소스. 풀·증분·차분 백업, 병렬 처리, WAL archive, 외부 저장소(S3·Azure·GCS·SFTP)·암호화·체크섬·자체 복구 시나리오 검증을 모두 지원합니다.

핵심 기능

기능메모
풀 / 증분 / 차분 백업페이지 단위 증분
병렬 처리--process-max
외부 저장소S3 / Azure Blob / GCS / SFTP / 로컬
압축gzip / lz4 / zstd / bz2
암호화AES-256-CBC
체크섬 검증백업·복원 양쪽
보존 정책풀 N개·일 단위
timeline 인식 PITR시점·LSN·xid
async archive_command처리량 ↑
stanza 단위 격리한 호스트가 여러 클러스터 백업

설치

# RHEL/Rocky (PGDG)
sudo dnf install -y pgbackrest

# Debian/Ubuntu
sudo apt-get install -y pgbackrest

기본 설정 — /etc/pgbackrest.conf

[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=3
repo1-retention-diff=14
compress-type=zst
compress-level=3
process-max=4
log-level-console=info
log-level-file=detail

[main]
pg1-path=/var/lib/pgsql/17/data
pg1-port=5432
pg1-user=postgres
섹션의미
[global]모든 stanza에 공통
[main]stanza 이름 — 임의의 식별자

stanza 만들기

sudo -u postgres pgbackrest --stanza=main stanza-create
sudo -u postgres pgbackrest --stanza=main check

check는 archive_command가 정상 동작하는지 검증합니다.

PostgreSQL 측 설정

# postgresql.conf
archive_mode = on
archive_command = 'pgbackrest --stanza=main archive-push %p'

reload.

백업

# 풀 백업
sudo -u postgres pgbackrest --stanza=main backup --type=full

# 증분 (마지막 백업 대비)
sudo -u postgres pgbackrest --stanza=main backup --type=incr

# 차분 (마지막 풀 대비)
sudo -u postgres pgbackrest --stanza=main backup --type=diff

기본은 마지막 풀 백업이 없으면 풀, 있으면 증분.

백업 목록

sudo -u postgres pgbackrest --stanza=main info
stanza: main
    status: ok
    cipher: none
    db (current)
        wal archive min/max (17): 000000010000000000000005/000000010000000000000023
        full backup: 20260520-020000F
            timestamp start/stop: 2026-05-20 02:00:00 / 2026-05-20 02:08:23
            database size: 240GB, backup size: 240GB
            repository size: 53.4GB, repository backup size: 53.4GB
        incr backup: 20260521-020000F_20260521-020000I
            timestamp start/stop: 2026-05-21 02:00:00 / 2026-05-21 02:01:12
            database size: 240GB, backup size: 1.2GB
            repository size: 53.7GB, repository backup size: 280MB

복원

# 가장 최근 백업으로 전체 복원
sudo -u postgres pgbackrest --stanza=main restore

# 특정 백업
sudo -u postgres pgbackrest --stanza=main restore --set=20260520-020000F

# PITR
sudo -u postgres pgbackrest --stanza=main restore \
  --type=time --target='2026-05-23 09:50:00' \
  --target-action=promote
--type의미
default백업 시점 직후까지
immediatebase 일관성 회복 직후
time--target=... 시각
xid트랜잭션 ID
lsnLSN
namenamed restore point

PGDATA가 비어 있어야 복원 가능합니다. --delta 옵션은 차이만 갱신.

외부 저장소

S3

[global]
repo1-type=s3
repo1-s3-bucket=my-pg-backups
repo1-s3-region=ap-northeast-2
repo1-s3-endpoint=s3.ap-northeast-2.amazonaws.com
repo1-s3-key=AKIAxxxxxxxxxxxxxxxx
repo1-s3-key-secret=xxxxxxxxxxxxxxxxxxxx
repo1-path=/pgbackrest

Azure Blob

repo1-type=azure
repo1-azure-account=mystorageaccount
repo1-azure-container=pgbackups
repo1-azure-key=xxxxxxxxxxxxxxxxxxxxxxxx

다중 repo

[global]
repo1-path=/var/lib/pgbackrest          # 로컬 SSD
repo2-type=s3                            # S3 오프사이트
repo2-s3-bucket=...

로컬 + S3 동시. 빠른 복원은 로컬, 장기 보존은 S3.

보존 정책

repo1-retention-full=3              # 풀 백업 3개 보관
repo1-retention-full-type=count      # 또는 'time'
repo1-retention-diff=14              # 차분 14개
repo1-retention-archive=14           # archive WAL 보존 일수

pgbackrest expire로 명시 정리도 가능 — 자동 expire는 backup 명령에 포함합니다.

검증 — verify

sudo -u postgres pgbackrest --stanza=main verify

저장된 백업의 체크섬을 검증해 저장 도중 손상 검출. 운영 정기 작업에 포함합니다.

운영 자동화

# crontab — sudo -u postgres
30 2 * * 0   pgbackrest --stanza=main --type=full backup
30 2 * * 1-6 pgbackrest --stanza=main --type=incr backup
0  4 * * 0   pgbackrest --stanza=main verify

일요일 풀 + 평일 증분 + 일요일 verify. Cron의 결과는 PostgreSQL 로그 또는 외부 모니터링으로 통합합니다.

자주 쓰는 옵션

옵션의미
--process-max=N병렬 워커 수
--compress-type=zst압축 알고리즘
--start-fast시작 즉시 체크포인트
--archive-asyncarchive_command 비동기 (처리량 ↑)
--repo1-cipher-type=aes-256-cbc암호화
--repo1-cipher-pass='...'암호화 키

async archive_commandarchive_command가 큐에 쌓고 별도 프로세스가 push — TPS 높은 시스템에서 archive lag 줄입니다.

archive-async=y
spool-path=/var/spool/pgbackrest

delta 복원

--delta는 PGDATA에 일부 파일이 있어도 변경 부분만 갱신. 큰 클러스터 재복원 시 시간 절약합니다.

pgbackrest --stanza=main --delta restore

체크섬 비교로 이미 같은 파일은 건너뜀. 단, 잘못 쓰면 일관성 깨질 위험 — 운영자가 명확히 이해 후.

모니터링

# 정상 stanza
pgbackrest --stanza=main info --output=json

JSON 출력을 Prometheus exporter(직접 제작 또는 pgbackrest-exporter)로 노출합니다. 알람:

  • 마지막 백업이 24시간 이상 안 됨
  • 백업 실패
  • WAL archive lag 큼

운영 안티패턴

안티패턴위험
pgbackrest backup만 돌리고 verify·복원 검증 안 함사고 시 복원 실패
repo가 같은 호스트 디스크에만호스트 사고 시 같이 사라짐
repo1-retention-archive가 풀 백업보다 짧음PITR window가 base 백업 사이클보다 좁아짐
같은 stanza 이름을 두 클러스터에서 사용서로 덮어씀
postgres user가 pgBackRest 명령 못 실행권한 문제
보존 정책 설계 시 archive 보존 > 풀 보존 권장. 풀 백업 3개(3주) 보존인데 archive를 14일만 두면, 3주 전 풀에서 시작한 PITR이 불가능합니다. archive 보존을 가장 오래된 백업 + 충분한 여유로 잡아야.

정리

  • pgBackRest = 운영 PostgreSQL 백업의 표준 도구
  • stanza 단위로 클러스터 분리, 다중 repo로 로컬 + S3 동시
  • 풀/증분/차분 + WAL archive + PITR 통합 관리
  • --archive-async로 archive lag 최소화
  • verify·복원 검증·외부 저장소 + 모니터링이 운영 셋
  • 보존 정책: archive 보존 > 풀 보존

다음 절(11.6)에서는 대안 도구 — Barman을 봅니다.