contrib/backup-restore/README.md
Warning: These scripts are provided as-is in the contrib/backup-restore directory. They are not officially maintained or supported by the Harbor project. Use them at your own risk and ensure you understand their functionality before running them in a production environment.
These scripts (harbor-backup and harbor-restore) are provided as a convenience for backing up and restoring your Harbor instance. They aim to back up the following components:
harbor.yml)Compared to the scripts the harbor project used to have in their repo this set of scripts is more robust in its error handling and also offers features for not packing the backup into a tarball. This makes it easy to rsync the whole backup directory to a secondary/standby node and restore there.
rsync is used extensively by the script. by leaving the files in the backup directory between runs the downtime for backup is greatly reduced at the expense of disk space usage.
Supports logging of status messages directly to syslog
docker command-line interface to interact with Harbor's containers. Ensure Docker is installed and accessible on the machine where you run these scripts.sudo or being in the docker group) to run Docker commands and perform file system operations.harbor-backup or harbor-restore script to avoid data inconsistencies.harbor-backup)Download the Scripts: Place the harbor-backup script in a location accessible from your Harbor instance. Within the Harbor repository, this would typically be under contrib/backup-restore/.
Make it Executable:
chmod +x harbor-backup
Run the Backup Script:
./harbor-backup [OPTIONS]
Stop Harbor: Ensure your Harbor instance is completely stopped before proceeding with the backup.
Options:
--docker-cmd <command>: Specify the Docker command to use (default: docker).--db-image <image>: Specify the Harbor database image to use for the temporary backup container (default: auto-detected). It's generally recommended to let it auto-detect.--db-path <path>: Harbor DB data path (default: /data/database). Adjust if your deployment uses a different path.--registry-path <path>: Registry data path (default: /data/registry). Adjust if your deployment uses a different path.--chart-museum-path <path>: Chart Museum data path (default: /data/chart_storage). Adjust if your deployment uses a different path.--redis-path <path>: Redis data path (default: /data/redis). Adjust if your deployment uses a different path.--secret-path <path>: Secret data path (default: /data/secret). Adjust if your deployment uses a different path.--config-path <path>: Harbor configuration file path (default: /etc/harbor/harbor.yml). Adjust if your deployment uses a different path.--backup-dir <path>: Directory where the backup will be stored (default: harbor_backup).--no-archive: Do not create a tar.gz archive of the backup directory. The backup will remain as a directory structure in $BACKUP_DIR/harbor.--use-syslog: Use syslog for logging output.--log-level <level>: Set the logging level (default: INFO, options: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY).--help: Display this help message.Backup Location: By default, the backup will be created in a directory named harbor_backup in the current working directory. If the --no-archive option is not used, the final backup will be a compressed tarball named harbor_backup.tar.gz within the harbor_backup directory.
harbor-restore)Download the Scripts: Place the harbor-restore script in a location accessible from your Harbor instance. Within the Harbor repository, this would typically be under contrib/backup-restore/.
Make it Executable:
chmod +x harbor-restore
Stop Harbor: Ensure your Harbor instance is completely stopped before proceeding with the restore.
Run the Restore Script:
./harbor-restore [OPTIONS]
Options: The restore script accepts similar options to the backup script, allowing you to specify the Docker command, database image, data paths, and the backup directory.
--backup-dir <path>: Crucially, this should point to the directory containing your Harbor backup (either the harbor subdirectory extracted from the tarball or the harbor_backup directory if --no-archive was used).--no-archive: Use this option if your backup is already extracted into the $BACKUP_DIR/harbor directory. If your backup is a tar.gz file, do not use this option; the script will attempt to extract it.(Other options like --docker-cmd, --db-image, --db-path, --registry-path, --chart-museum-path, --redis-path, --secret-path, --config-path, --use-syslog, and --log-level function similarly to the backup script.)
Restore Process: The script will:
--no-archive).Restart Harbor: Once the restore script completes successfully, you can restart your Harbor instance.
--db-image option in both the backup and restore scripts to ensure consistency.contrib/backup-restore/ directory. They may not be actively maintained, and you might encounter issues. Contributions and improvements from the community are welcome.If you find issues or have improvements to these scripts, feel free to submit pull requests to the Harbor project in the contrib/backup-restore/ directory.