Skip to content
Blog

Running the Registry with Persistent Storage and Backups

Operational guide for backing up and restoring container registries, snapshotting S3/filesystem storage, backing up htpasswd/database state, and verifying disaster recovery.

Published on • November 18, 2026

AI Assistant

Container registries store business-critical production assets, build history, and deployment base layers. If a registry host suffers disk failure or corruption without backups, build pipelines halt and Kubernetes nodes cannot scale or recover from pod restarts.

Backup and disaster recovery for OCI registries involves snapshotting three core components: Layer & Manifest Storage, Registry Configurations & TLS Certificates, and User Authentication / Metadata Databases.

In this operational guide, we will design an automated backup strategy for self-hosted registries, write backup scripts for filesystem and S3 backends, and demonstrate a disaster recovery restoration drill.

The Three Elements of a Registry Backup

+-----------------------------------------------------------------------------------+
| 1. Layer & Manifest Blobs (`/var/lib/registry` or S3 Bucket)                      |
|    - Contains all image layers, manifests, tags, and digests.                     |
|    - Accounts for 99% of storage footprint.                                       |
+-----------------------------------------------------------------------------------+
| 2. Configuration & Authentication Files (`config.yml`, `htpasswd`)                |
|    - Contains server settings, TLS keys, and user password hashes.                |
+-----------------------------------------------------------------------------------+
| 3. Database State (Harbor PostgreSQL / Redis Cache)                               |
|    - Required for registries like Harbor that maintain metadata in PostgreSQL.    |
+-----------------------------------------------------------------------------------+

Method 1: Backing Up Filesystem-Based Registries

If your registry uses the filesystem storage driver mounted at /opt/registry/data:

Step 1: Automated Nightly Backup Script (registry-backup.sh)

#!/usr/bin/env bash
set -euo pipefail

BACKUP_DIR="/mnt/backups/registry/$(date +%Y-%m-%d)"
REGISTRY_DATA="/opt/registry/data"
REGISTRY_AUTH="/opt/registry/auth"
REGISTRY_CONFIG="/opt/registry/config.yml"

echo "[$(date)] Starting Registry Backup to $BACKUP_DIR..."

mkdir -p "$BACKUP_DIR"

# 1. Back up configuration & auth files
cp -r "$REGISTRY_AUTH" "$BACKUP_DIR/auth"
cp "$REGISTRY_CONFIG" "$BACKUP_DIR/config.yml"

# 2. Freeze registry during filesystem sync OR perform atomic rsync snapshot
# Using rsync to copy blob storage cleanly
rsync -az --delete "$REGISTRY_DATA/" "$BACKUP_DIR/data/"

# 3. Compress snapshot archive
tar -czf "$BACKUP_DIR.tar.gz" -C "$BACKUP_DIR" .
rm -rf "$BACKUP_DIR"

echo "[$(date)] Backup Completed: $BACKUP_DIR.tar.gz"

Method 2: Backing Up S3-Backed Registries

If your registry uses AWS S3 (or MinIO) for blob storage, physical file backups are replaced with cloud-native snapshot strategies:

+-----------------------------------------------------------------------------------+
| S3 Storage Backup Strategy                                                        |
|  1. Enable S3 Bucket Versioning (Protects against accidental mass deletions).      |
|  2. Configure Cross-Region Replication (CRR) to a secondary AWS region bucket.   |
|  3. Set Object Lock / Write-Once-Read-Many (WORM) for ransomware protection.      |
+-----------------------------------------------------------------------------------+

Enabling S3 Cross-Region Replication via AWS CLI:

aws s3api put-bucket-replication \
  --bucket my-primary-registry-bucket \
  --replication-configuration file://s3-replication-config.json

Method 3: Backing Up Enterprise Harbor Registries

Project Harbor stores user roles, project policies, scan reports, and tag metadata inside a PostgreSQL database.

Executing Harbor Database Dump:

# Dump Harbor PostgreSQL database
docker exec -t harbor-db pg_dump -U postgres registry > harbor-db-$(date +%F).sql

# Dump Harbor Redis session store
docker exec -t harbor-redis redis-cli SAVE

Disaster Recovery Drill: Restoring a Registry from Scratch

Testing your restoration process periodically guarantees that backups actually work during real emergencies.

Step 1: Restore Directory Layout & Auth

mkdir -p /opt/registry/data /opt/registry/auth

# Extract backup archive
tar -xzf /mnt/backups/registry/2026-11-18.tar.gz -C /tmp/restore_temp

cp -r /tmp/restore_temp/auth/* /opt/registry/auth/
cp -r /tmp/restore_temp/data/* /opt/registry/data/
cp /tmp/restore_temp/config.yml /opt/registry/config.yml

Step 2: Relaunch Registry Container

docker run -d \
  -p 5000:5000 \
  --name restored-registry \
  --restart=always \
  -v /opt/registry/data:/var/lib/registry \
  -v /opt/registry/auth:/auth \
  -e REGISTRY_AUTH=htpasswd \
  -e REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" \
  -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
  registry:2

Step 3: Test Image Restoration Integrity

# Login and pull a restored image
docker login localhost:5000 -u registryuser -p SuperSecret123!
docker pull localhost:5000/my-alpine:v1

If the pull completes cleanly and the SHA-256 digest matches your original image, your disaster recovery test is verified!


Summary Backup Checklist

AssetBackup FrequencyTarget Destination
Configuration (config.yml)On ChangeVersion control / Secure Backup
Auth (htpasswd / Keys)On ChangeEncrypted Secret Vault
Image Layers (/var/lib/registry)DailyOffsite NFS / S3 Cross-Region Bucket
Harbor Database (PostgreSQL)DailyCompressed SQL dump offsite

Regularly backing up registry storage and executing disaster recovery drills ensures business continuity and protects application build history.