Skip to main content

Automated TrueNAS OS Backup

The past month has been full of configuration changes to my server, and this is a continuation of that. My OS drive runs on a single SSD, mostly because I ran out of SATA cables when I built it. This isn't a big deal to me, since I’ve been taking manual backups of the configuration, but I decided it was time to automate the process while keeping it mostly GUI-based so that the backup settings would be included in the backup I was making.

After a bit of digging, I found the best way to grab the configuration file and secret key was through the API. All of this was done on Fangtooth 25.04.

Here are the steps I took.

  1. Create API token
  2. Create dataset for the saved files
  3. Login and setup a cloud storage account within TrueNAS
  4. Drop the backup script into dataset that was created
  5. Create a cron job to run the script.
  6. Configure a Cloud Sync Task to push and sync the dataset to the cloud account.

In the first step, I generated an API token and copied it to a safe location. TrueNAS will only show you this token the one time so it's important to save it somewhere safe.

Then create a dataset, I named mine osrecovery on my data pool.

For cloud storage, I used the Cloud Sync Tasks wizard to set up my preferred provider, this allows TrueNAS to push the backups automatically on a schedule.

Then, I placed the following backup script into the dataset. Initially, I threw the curl command into a shell script and ran it manually, but Copilot helped clean it up for readability. You'll need to chmod +x the script and test it manually with: sudo bash script.sh

#!/bin/bash

API_KEY="1234567890"

BACKUP_DIR="/mnt/yourpool/yourdataset/"

TIMESTAMP=$(date +"%Y-%m-%d_%H-%M-%S")

BACKUP_FILE="$BACKUP_DIR/truenas_config_$TIMESTAMP.tar"


curl -X POST "https://host/api/v2.0/config/save" \

     -H "Authorization: Bearer $API_KEY" \

     -H "Content-Type: application/json" \

     -d '{"secretseed": true}' \

     -o "$BACKUP_FILE"

With the script in place, I set up a cron job under System > Advanced Settings to run monthly. I may change this to weekly to catch any quick configuration changes.

/bin/bash /mnt/yourpool/yourdataset/script.sh

Finally, in GUI > Data Protection > Cloud Sync Tasks, I added a new sync task to push and sync the dataset and backup files to my cloud provider. Since this is a sync operation, it won’t overwrite data, only push new files.

This setup was surprisingly easy to configure after some planning and a bit of time on the TrueNAS forums. I feel much better knowing that in a worst-case scenario, I'll have a recent backup to use if needed.

An alternative to this I stumbled across was performing a similar setup but using a separate Windows PC. That information can be found here: https://www.pickysysadmin.ca/2025/05/06/automated-truenas-configuration-backups/#comment-479800 


Comments