# 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 1. Push this code to a GitHub repository 2. Ensure the repository has write permissions for GitHub Actions ### 2. GitHub Secrets Configuration Add the following secrets to your GitHub repository: 1. Go to your repository → Settings → Secrets and variables → Actions 2. 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`](.github/workflows/backup.yml:10): ```yaml schedule: - cron: '0 2 * * *' # Daily at 2 AM UTC ``` ### 4. Manual Execution You can manually trigger the backup from the GitHub UI: 1. Go to your repository → Actions → "Nomad Backup" workflow 2. Click "Run workflow" → "Run workflow" ## How It Works 1. **Checkout**: The workflow checks out your repository 2. **Setup**: Installs Python and required dependencies 3. **Backup**: Runs the [`backup.py`](backup.py:1) script to fetch Nomad job specifications 4. **Commit**: If changes are detected, commits them to the repository 5. **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: ```bash # 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 1. **Connection Timeout**: Ensure `NOMAD_ADDR` is correct and accessible 2. **Authentication Failure**: Verify `NOMAD_TOKEN` is valid and has read permissions 3. **No Changes Committed**: This is normal when job configurations haven't changed ### Debug Mode To debug the GitHub Actions workflow, you can: 1. Add `-v` flag to the backup command in the workflow 2. Check the Actions logs for detailed error messages ## License This project is open source and available under the MIT License.