This repository provides an automated backup script for TrueNAS SCALE configuration files using Bash and Git. The script downloads the TrueNAS config via API, stores it (optionally with secret seed), manages backup retention, and can push the backup files to a GitHub repository for offsite storage.
- Automated config backups using the TrueNAS API
- Optionally includes Secret Seed for full disaster recovery
- Backup retention: automatically deletes oldest backups beyond a set limit
- Git integration: stores backups in a Git repository and pushes to GitHub
- Versioned directories: Backups are organized by TrueNAS version
- Bash shell (Linux/UNIX environment, tested on TrueNAS SCALE)
- curl
- git
- A GitHub repository for remote backup storage
- TrueNAS API key with config backup permissions
-
Clone this repository or download the script
git clone https://github.com/cavazos-apps/truenas-backup-script.git cd truenas-backup-script
-
Edit the script variables
Open
backup_config.sh
in your favorite editor and configure these variables at the top:serverURL="http(s)://<your-truenas-ip-or-host>" apiKey="<your-api-key>" secSeed=true # true to include Secret Seed, false otherwise backuploc="/path/to/backup/location" maxnrOfFiles=7 # Number of backups to keep (0 = unlimited) gitUrl="[email protected]:youruser/yourrepo.git"
-
Make the script executable
chmod +x backup_config.sh
-
Run the script
./backup_config.sh
- Retrieves the current TrueNAS version to create versioned backup directories
- Uses the TrueNAS API to download the config file (optionally with Secret Seed)
- Stores the backup file in
$backuploc/<version>/
- Keeps only the latest
$maxnrOfFiles
backups (unless set to 0) - Initializes a Git repo (if needed), commits changes, and pushes to your remote GitHub repo
- Ensure your API Key and URLs are correct. The script will not validate backup integrity.
- Backups with Secret Seed are essential for full system restoration, but should be stored securely.
- GitHub repo must be initialized and accessible via SSH or HTTPS depending on your
gitUrl
. - The script is intended to be run manually or via cron for scheduled backups.
Thanks to ‘NasKar’ and ‘engedics’ for sharing ideas on the TrueNAS forums.