Hugo Source Backup

Hugo Source Backup

Web

πŸ”’ Hugo Source Backup #

This guide outlines how to back up your Hugo source files (excluding the public/ folder) to a private GitHub repository.


πŸ“ Folder Structure #

Typical Hugo project structure:

hugo-site/
β”œβ”€β”€ archetypes/
β”œβ”€β”€ content/
β”œβ”€β”€ layouts/
β”œβ”€β”€ static/
β”œβ”€β”€ themes/
β”œβ”€β”€ config.toml
β”œβ”€β”€ public/           # <- This is ignored for source backup
└── backup.sh         # Backup script

βœ… 1. Create a Private GitHub Repo #

  • Go to https://github.com/new
  • Name it something like hugo-source
  • Set visibility to Private
  • Don’t initialize with README or license

βœ… 2. Initialize Git in Your Hugo Site (if not already) #

git init
git remote add origin https://github.com/<your-username>/hugo-source.git
echo "public/" >> .gitignore

βœ… 3. Create the Backup Script #

Create a file named backup.sh in the root of your Hugo project:

#!/bin/bash
git add .
git commit -m "πŸ”’ Backup: $(date +'%Y-%m-%d %H:%M:%S')"
git push origin main
echo "βœ… Backup Complete!"

Make it executable:

chmod +x backup.sh

βœ… 4. Use It! #

To back up your source files:

./backup.sh

πŸ“ Notes #

  • Only your source files are backed up.
  • The public/ folder is excluded (it’s where the generated site lives).
  • Combine with deploy.sh for full workflow automation.