Overview
The compactor merges older incremental backups into new full snapshots, reducing storage usage and improving restore performance. It reads compaction policies from the cloud configuration file.
Manual Usage
# Dry-run (default) — prints planned actions without modifying anything
xreplicator compact --repo /var/lib/backup/repo
# Actually perform compaction
xreplicator compact --repo /var/lib/backup/repo --dry-run=false
# Use a custom cloud config
xreplicator compact --repo /var/lib/backup/repo --cloud-config /etc/xreplicator/cloud-config.yaml| Flag | Required | Default | Description |
|---|---|---|---|
--repo | Yes | — | Repository path |
--cloud-config | No | <repo>/cloud-config.yaml | Cloud config path |
--dry-run | No | true | Print actions without modifying snapshots |
Compaction Policies
Policies are defined in cloud-config.yaml under the compaction.policies section.
Policy Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique policy name |
enabled | boolean | — | Enable/disable this policy (default: true) |
compact_to_full | boolean | — | Create a new full snapshot from compacted incrementals (default: true) |
rpo | duration | Yes | Compact snapshots older than this value (e.g., "24h") |
keep_snapshots | integer | No | Minimum recent snapshots to keep, even if older than RPO |
hostnames | string[] | No | Exact hostnames to match |
hostname_globs | string[] | No | Glob patterns for hostnames (e.g., ["prod-*"]) |
device_paths | string[] | No | Exact device paths to match |
device_path_globs | string[] | No | Glob patterns for device paths |
Use either hostnames or hostname_globs — not both. Same applies to device_paths vs device_path_globs.
How Compaction Works
- Policy Evaluation — Reads all enabled policies from the cloud config
- Snapshot Selection — Finds snapshots matching hostname/device criteria
- Age Filtering — Filters snapshots older than the RPO, respecting
keep_snapshots - Compaction — Merges selected incrementals into a new full snapshot
- Cleanup — Deletes old incrementals that were compacted
- Chain Update — Updates parent links in remaining snapshots
Configuration Examples
Daily Compaction (All Devices)
compaction:
policies:
- name: "daily-compaction"
enabled: true
compact_to_full: true
rpo: "24h"
keep_snapshots: 10
hostname_globs: ["*"]
device_path_globs: ["*"]Weekly Compaction (Production Servers)
compaction:
policies:
- name: "weekly-production"
enabled: true
compact_to_full: true
rpo: "168h" # 1 week
keep_snapshots: 5
hostnames: ["prod-server-01", "prod-server-02"]
device_paths: ["/dev/sda"]Multiple Policies
compaction:
policies:
- name: "daily-all"
enabled: true
compact_to_full: true
rpo: "24h"
hostname_globs: ["*"]
device_path_globs: ["*"]
- name: "weekly-production"
enabled: true
compact_to_full: true
rpo: "168h"
keep_snapshots: 10
hostname_globs: ["prod-*"]
- name: "monthly-archive"
enabled: true
compact_to_full: true
rpo: "720h" # 30 days
keep_snapshots: 3
hostname_globs: ["archive-*"]Scheduling with systemd Timer
If you want scheduled compaction, create your own systemd timer that runs the
xreplicator compact command from the backup-server package.
You can also schedule compaction from the Web UI: go to Settings and configure the compaction schedule there. You can also create and edit compaction policies directly from the UI.
Last updated on