Incremental database backup setup

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Setting Up Incremental Database Backups

Full database dumps every night are expensive in disk space and time, especially when the database occupies tens of gigabytes. Incremental backups save only changes since the last backup.

Types of incremental backups

Differential — saves all changes since the last full backup. Restore: full + one differential.

Incremental — saves only changes since the last any backup. Restore: full + chain of incrementals.

WAL-based (PostgreSQL) — continuous transaction log archiving, foundation for PITR.

PostgreSQL: WAL archiving via pgBackRest

# /etc/pgbackrest/pgbackrest.conf
[global]
repo1-path=/var/lib/pgbackrest
repo1-retention-full=2
repo1-retention-diff=7
log-level-console=info

[myapp]
pg1-path=/var/lib/postgresql/14/main

Initialization and first full backup:

pgbackrest --stanza=myapp stanza-create
pgbackrest --stanza=myapp --type=full backup

Subsequent incremental backups:

# Differential (once a week)
pgbackrest --stanza=myapp --type=diff backup

# Incremental (daily)
pgbackrest --stanza=myapp --type=incr backup

Cron schedule:

# Full backup once a week (Sunday 01:00)
0 1 * * 0  pgbackrest --stanza=myapp --type=full backup
# Differential (Mon-Sat 01:00)
0 1 * * 1-6 pgbackrest --stanza=myapp --type=diff backup

MySQL: Percona XtraBackup

The only tool supporting true incremental MySQL backups without locks:

# Full backup
xtrabackup --backup --target-dir=/var/backups/mysql/full/

# First incremental
xtrabackup --backup \
  --target-dir=/var/backups/mysql/incr1/ \
  --incremental-basedir=/var/backups/mysql/full/

# Second incremental (based on incr1)
xtrabackup --backup \
  --target-dir=/var/backups/mysql/incr2/ \
  --incremental-basedir=/var/backups/mysql/incr1/

Restore:

# Prepare full backup
xtrabackup --prepare --apply-log-only --target-dir=/var/backups/mysql/full/

# Apply incrementals
xtrabackup --prepare --apply-log-only \
  --target-dir=/var/backups/mysql/full/ \
  --incremental-dir=/var/backups/mysql/incr1/
xtrabackup --prepare \
  --target-dir=/var/backups/mysql/full/ \
  --incremental-dir=/var/backups/mysql/incr2/

Cloud storage and deduplication

Tools with built-in deduplication and compression significantly reduce storage volume:

  • Restic — encrypted incremental backups to S3/GCS/B2/SSH
  • Borg Backup — block-level deduplication
  • Duplicati — with web interface
# Restic: initialize repository
restic -r s3:s3.amazonaws.com/my-bucket/db-backups init

# Backup directory with dumps
restic -r s3:s3.amazonaws.com/my-bucket/db-backups \
  backup /var/backups/postgres/ \
  --password-file /etc/restic-password

Monitoring and alerting

Metrics to monitor:

  • Size of last backup (sharp decrease — problem signal)
  • Backup execution time
  • Successful healthcheck ping
# End of script — check and healthcheck
if pgbackrest --stanza=myapp check; then
  curl -s "https://hc-ping.com/${HC_UUID}"
else
  curl -s "https://hc-ping.com/${HC_UUID}/fail"
fi

Timeline

Setup of pgBackRest or XtraBackup with incremental strategy — 1–2 business days.