Docker-harbor-backup

From PheonixSolutions
Jump to navigation Jump to search

Harbor Backup & Restore Guide

πŸ“Œ Overview

This document outlines the steps to backup and restore a Harbor registry setup on the server. It includes a custom backup script, storage paths, S3 upload details, and a step-by-step restore process.

πŸ”„ Backup Process

πŸ“ Script Location

The backup script is located at:

/home/pheonix/harbor/backup_harbor.sh

πŸ“‹ What the Script Does

  • Dumps the Harbor PostgreSQL database using pg_dumpall.
  • Archives the following essential files and directories:
    • /root/harbor/harbor.yml
    • /root/harbor/install.sh
    • /root/harbor/docker-compose.yml
    • /root/harbor/prepare
    • /root/harbor/common/
    • /data/ – Contains Harbor image layers, configurations, and certificates.
    • The SQL dump file generated.

πŸ“‚ Backup Output

After running the script, the following files are generated locally:

/opt/harbor/backups/

β”œβ”€β”€ harbor_backup_<timestamp>.tar.gz

└── harbor_backup_<timestamp>_db.sql

☁️ Upload Destinations

Backup files are uploaded to:

  • Local Directory: /opt/harbor/backups/
  • AWS S3 Bucket: s3://docker-harbor-pheonix/ (docker-harbor-pheonix)

♻️ Harbor Restore Procedure

πŸ” Step 1: Download Backup Files

Use the following commands to download the latest backup files from S3:

aws s3 cp s3://docker-harbor-pheonix/harbor_backup_<timestamp>.tar.gz /tmp/

aws s3 cp s3://docker-harbor-pheonix/harbor_backup_<timestamp>_db.sql /tmp/

πŸ“¦ Step 2: Extract Archive

⚠️ Important: Untar the archive at the root "/" directory. Do not extract in /tmp, /home, or other directories β€” this could break path structure.

cd /

tar -xzf /tmp/harbor_backup_<timestamp>.tar.gz

This will restore:

  • /root/harbor/ – Harbor installation files
  • /data/ – Registry data, configs, certs
  • /var/log/harbor/ – Harbor logs
  • /opt/harbor/backups/ – DB dump file

πŸ› οΈ Step 3: Restore the Database

Start the database container:

cd /root/harbor

./prepare

docker-compose up -d harbor-db

sleep 10

Restore the database:

cat /opt/harbor/backups/harbor_backup_<timestamp>_db.sql | docker exec -i harbor-db psql -U postgres

πŸš€ Step 4: Start All Harbor Services

cd /root/harbor & ./prepare

docker-compose up -d

βœ… Step 5: Access and Verify

Open your browser and visit:

https://dockerhub.pheonixsolutions.com

Check if:

  • Harbor UI loads correctly
  • Project and image data are intact
  • Logs show normal activity

πŸ“Ž Notes

  • Ensure the S3 credentials used by the script have write permissions to the harbor-backups/ folder.
  • Backup script should be scheduled via cron for regular automated backups.
  • Always verify space availability on /opt and /data before starting a restore.