{"id":9176,"date":"2025-07-29T10:17:16","date_gmt":"2025-07-29T04:47:16","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=9176"},"modified":"2025-07-29T10:17:22","modified_gmt":"2025-07-29T04:47:22","slug":"harbor-dockerhub-backup-and-restore-guide","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/harbor-dockerhub-backup-and-restore-guide\/","title":{"rendered":"Harbor &#8211; Dockerhub Backup and Restore Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"> Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Harbor is a popular, open-source container image registry that secures images with role-based access control, supports image replication, and integrates with external authentication systems. Like any registry, it&#8217;s critical to <strong>regularly back up your Harbor instance<\/strong>, including the database, image storage, configuration, and SSL certificates. This guide provides step-by-step instructions to automate Harbor backups and restore them when needed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, ensure the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Docker is installed<\/li>\n\n\n\n<li>Harbor is installed via <strong>Docker Compose<\/strong> (e.g., <code>\/root\/harbor<\/code>)<\/li>\n\n\n\n<li>Your data directory is located at <code><strong>\/data<\/strong><\/code><\/li>\n\n\n\n<li>Optional: AWS CLI configured for S3 upload<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">DNS Configuration<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Your Harbour instance should be accessible via a valid domain (e.g., <code>dockerhub.&lt;yourdomain&gt;.com<\/code>) and DNS A record should point to your server&#8217;s public IP.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Backup Strategy Overview<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Your backup process should include the following components:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>PostgreSQL Database<\/strong><br>Harbor stores metadata and configuration in its internal PostgreSQL database (<code>harbor-db<\/code>). Dumping this database is critical for a full restore.<\/li>\n\n\n\n<li><strong>Harbor Configuration Files<\/strong><br>These are typically stored under your Harbor installation directory (e.g., <code>\/root\/harbor<\/code>).<\/li>\n\n\n\n<li><strong>Image and Artifact Storage<\/strong><br>All image layers and associated files are stored under <code>\/data<\/code>. This folder must be archived during backup.<\/li>\n\n\n\n<li><strong>Logs and SSL Certificates<\/strong><br>Include log directories and any SSL certificates stored within Harbor&#8217;s directories.<\/li>\n\n\n\n<li><strong>Automation<\/strong><br>Create a custom script that compresses the above components into a single archive and optionally uploads it to a cloud storage bucket (e.g., S3).<\/li>\n\n\n\n<li><strong>Retention Policy<\/strong><br>Implement a mechanism to retain only the latest few backups (e.g., last 5 backups) to conserve disk space.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Backup Process \u2013 Key Steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can design a backup script that performs the following actions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a backup directory (e.g., <code>\/opt\/harbor\/backups<\/code>)<\/li>\n\n\n\n<li>Generate a timestamped filename<\/li>\n\n\n\n<li>Dump the <strong>Harbor PostgreSQL database<\/strong> (<code>harbor-db<\/code>) to a SQL file<\/li>\n\n\n\n<li>Archive the following:\n<ol class=\"wp-block-list\">\n<li>Harbor configuration directory (<code>\/root\/harbor<\/code>)<\/li>\n\n\n\n<li>Image and data storage directory (<code>\/data<\/code>)<\/li>\n\n\n\n<li>Database dump file<\/li>\n\n\n\n<li>Harbor logs (<code>\/var\/log\/harbor<\/code>) and SSL certs (if applicable)<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>(Optional) Upload the archive to AWS S3 or another remote location<\/li>\n\n\n\n<li>Automatically remove older backups beyond a set limit (e.g., keep only 5 recent archives)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Restore Process \u2013 Key Steps<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To restore a Harbor instance from backup:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Extract Backup Archive<\/strong><br>Unpack the desired backup archive in your backup directory (e.g., <code>\/opt\/harbor\/backups<\/code>).<\/li>\n\n\n\n<li><strong>Restore Database<\/strong>\n<ol class=\"wp-block-list\">\n<li>Start the <code>harbor-db<\/code> container only using Docker Compose.<\/li>\n\n\n\n<li>Import the previously dumped SQL file back into the database.<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li><strong>Restore Configuration and Data<\/strong>\n<ol class=\"wp-block-list\">\n<li>Place the extracted <code>harbor<\/code> directory back to its original path (<code>\/root\/harbor<\/code>)<\/li>\n\n\n\n<li>Replace the <code>\/data<\/code> directory with the backup copy (if necessary)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Verification<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Visit: <code>https:\/\/dockerhub.&lt;yourdomain&gt;.com<\/code><\/li>\n\n\n\n<li>Check web UI, repositories, and certs.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"> Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With Harbor storing critical container images and metadata, a reliable backup and restore process is non-negotiable. This guide provides a complete approach to safely back up Harbor&#8217;s components, automate the process, and ensure fast disaster recovery using Docker Compose. Ensure regular testing of your backups and consider off-site storage (e.g., S3) for production environments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Harbor is a popular, open-source container image registry that secures images with role-based access control, supports image replication, and [&hellip;]<\/p>\n","protected":false},"author":509,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1020],"tags":[],"class_list":["post-9176","post","type-post","status-publish","format-standard","hentry","category-containers-kubernetes","psol-cat-containers-kubernetes"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2o0","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/509"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=9176"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9176\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}