d9d19339343bbb58168a854d5eea6c7ea511d7bf
Nomad Backup with GitHub Actions
This project provides an automated backup solution for HashiCorp Nomad job specifications using GitHub Actions. Instead of creating timestamped backup folders, it uses Git's version control to track changes to your Nomad job configurations.
Features
- Automated Backups: Runs daily via GitHub Actions
- Git Version Control: Uses Git commits to track job configuration changes
- Dual Format Support: Backs up both HCL and JSON job specifications
- Secure: Uses GitHub Secrets for Nomad API credentials
- Manual Trigger: Can be run on-demand via GitHub UI
Setup Instructions
1. Repository Setup
- Push this code to a GitHub repository
- Ensure the repository has write permissions for GitHub Actions
2. GitHub Secrets Configuration
Add the following secrets to your GitHub repository:
- Go to your repository → Settings → Secrets and variables → Actions
- Add these secrets:
NOMAD_ADDR: Your Nomad API address (e.g.,https://nomad.example.com:4646)NOMAD_TOKEN: Your Nomad ACL token (if authentication is enabled)
3. Schedule Configuration
The workflow is configured to run daily at 2 AM UTC (6 PM PST). To modify the schedule, edit the cron expression in .github/workflows/backup.yml:
schedule:
- cron: '0 2 * * *' # Daily at 2 AM UTC
4. Manual Execution
You can manually trigger the backup from the GitHub UI:
- Go to your repository → Actions → "Nomad Backup" workflow
- Click "Run workflow" → "Run workflow"
How It Works
- Checkout: The workflow checks out your repository
- Setup: Installs Python and required dependencies
- Backup: Runs the
backup.pyscript to fetch Nomad job specifications - Commit: If changes are detected, commits them to the repository
- Push: Pushes the changes back to the remote repository
File Structure
├── .github/
│ └── workflows/
│ └── backup.yml # GitHub Actions workflow
├── backup.py # Main backup script
├── nomad_backup/ # Backup directory (created by script)
│ ├── job1.hcl # Job specifications in HCL format
│ ├── job2.json # Job specifications in JSON format
│ └── ...
└── README.md # This file
Local Usage
You can also run the backup script locally:
# Basic usage (connects to local Nomad)
python backup.py
# Connect to remote Nomad with token
python backup.py --addr https://nomad.example.com:4646 --token your-token
# Custom output directory
python backup.py --output /path/to/backups
Environment Variables
The script supports these environment variables:
NOMAD_ADDR: Nomad API address (default:http://localhost:4646)NOMAD_TOKEN: Nomad ACL token for authentication
Security Notes
- Never commit sensitive data or tokens to the repository
- Use GitHub Secrets for all credentials
- Review job specifications before committing to ensure no sensitive data is included
Troubleshooting
Common Issues
- Connection Timeout: Ensure
NOMAD_ADDRis correct and accessible - Authentication Failure: Verify
NOMAD_TOKENis valid and has read permissions - No Changes Committed: This is normal when job configurations haven't changed
Debug Mode
To debug the GitHub Actions workflow, you can:
- Add
-vflag to the backup command in the workflow - Check the Actions logs for detailed error messages
License
This project is open source and available under the MIT License.
Description
Languages
HCL
81.2%
Python
14.6%
Shell
4.2%