Docker-harbor-backup

From PheonixSolutions
Revision as of 13:02, 6 August 2025 by Tech team (talk | contribs) (Created page with " # πŸ›‘οΈ Harbor Backup & Restore Guide ## πŸ“Œ Overview This document outlines the steps to **backup** and **restore** a Harbor registry setup on the server. It includes a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)
Jump to navigation Jump to search
  1. πŸ›‘οΈ Harbor Backup & Restore Guide
    1. πŸ“Œ 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.


    1. πŸ”„ Backup Process
      1. πŸ“ Script Location

The backup script is located at:


`/home/pheonix/harbor/backup_harbor.sh`


      1. πŸ“‹ 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.
      1. πŸ“‚ 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

`

      1. ☁️ Upload Destinations

Backup files are uploaded to:

  • **Local Directory**: `/opt/harbor/backups/`
  • **AWS S3 Bucket**: `s3://openvz5-docker/harbor-backups/`


    1. ♻️ Harbor Restore Procedure
      1. πŸ” Step 1: Download Backup Files

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

```bash aws s3 cp s3://openvz5-docker/harbor-backups/harbor_backup_<timestamp>.tar.gz /tmp/ aws s3 cp s3://openvz5-docker/harbor-backups/harbor_backup_<timestamp>_db.sql /tmp/ ```

---

      1. πŸ“¦ 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.

```bash 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

---

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

Start the database container:

```bash cd /root/harbor docker-compose up -d harbor-db sleep 10 ```

Restore the database:

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

---

      1. πŸš€ Step 4: Start All Harbor Services

```bash cd /root/harbor docker-compose up -d ```

---

      1. βœ… 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

---

    1. πŸ“Ž 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.