2.6 KiB
2.6 KiB
AdGuardHome Config Backup Script
This project provides a Bash script to back up the AdGuardHome configuration file (AdGuardHome.yaml) from multiple remote servers via SSH.
The script supports:
- Backup of multiple servers defined in a
.envfile - Timestamped backup files named using the server's hostname
- Logging of each backup session
- Optional notifications via ntfy.sh and Discord
📦 Features
- SSH key authentication
- Environment-based configuration
- Per-host backup with hostname and timestamp
- Automatic log file generation
- Optional failure/success notifications
🛠️ Requirements
- Bash
sshandscpinstalled- A valid SSH private key
- Optional:
curl(for notifications)
🧾 Setup
1. Clone the repository
git clone https://github.com/youruser/adguard-backup-script.git
cd adguard-backup-script
2. Configure the .env file
Copy and edit the sample .env file:
# SSH Settings
HA_SSH_KEY="$HOME/.ssh/id_rsa"
HA_SSH_USER="youruser"
# Backup destination (local path)
BACKUP_DEST="/your/backup/directory"
# Remote config path (optional override)
REMOTE_FILE="/opt/AdGuardHome/AdGuardHome.yaml"
# List of remote servers (space-separated)
SERVER_LIST="server1.example.com server2.example.com 192.168.1.100"
# Notification options (optional)
NTFY_ENABLED=true
NTFY_SERVER="https://ntfy.yourdomain.com"
NTFY_TOPIC="adguard-backups"
DISCORD_ENABLED=true
DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
3. Make the script executable
chmod +x backup_adguard.sh
4. Run the backup
./backup_adguard.sh
🗂️ Backup Output
- Files saved to:
$BACKUP_DEST - Naming convention:
AdGuardHome.yaml-<hostname>-<timestamp> - Example:
AdGuardHome.yaml-server1-2025-06-23_14-45-01
🔔 Notifications (Optional)
ntfy
- Configure
NTFY_ENABLED=true,NTFY_SERVER, andNTFY_TOPICin your.env.
Discord
- Set
DISCORD_ENABLED=trueand supply yourDISCORD_WEBHOOK_URL.
🧪 Sanity Checks
The script will validate:
- SSH key path
- SSH user
- Backup destination
- Server list
- Notification credentials (if enabled)
📜 Log Files
Each run generates a log file:
- Location:
$BACKUP_DEST - Format:
backup-<timestamp>.log
Example:
backup-2025-06-23_14-45-01.log
💡 Tips
- Use cron to automate the script (e.g., daily backups).
- Ensure your SSH key is authorized on all target servers.
- Monitor logs or enable notifications for unattended runs.
📄 License
MIT License
🤝 Contributing
Feel free to fork, submit PRs, or suggest improvements!