TrueNAS - SCALE Create a local Backup and Send to S3 Buckets
To automate backing up your TrueNAS configuration directly to Amazon S3 or any S3-compatible cloud storage, you need to create a local backup script and pair it with a TrueNAS Cloud Sync task
TrueNAS automatically saves daily configuration databases locally to your system dataset, but exporting it safely off-site requires grabbing the full archive (with the secret seed) via a middleware command (midclt).
Step 1: Create a Local Dataset and Script
First, create an isolated directory on your storage pool where TrueNAS will output the configuration files before uploading them. [1]
- Navigate to Storage > Datasets and click Add Dataset. Name it something distinct like
system-backups.
- Open a shell or connection to your TrueNAS system. Create a script named
backup_config.sh inside that dataset folder:
nano /mnt/YOUR_POOL/system-backups/backup_config.sh
- Paste the following script, which requests the configuration archive from the TrueNAS API engine (
midclt), saves it with a timestamp, and purges backups older than 30 days to avoid clutter:
#!/bin/bash
BACKUP_DIR="/mnt/volume1/system-backups"
DATE=$(date +%Y%m%d-%H%M%S)
FILENAME="truenas-config-${DATE}.tar"
# 1. Request the configuration download job from the SCALE API
JOB_DATA=$(midclt call core.download "config.save" '[{"secretseed": true}]' "${FILENAME}")
# 2. Extract the download path cleanly using jq (returns: /_download/JOB_ID?auth_token=TOKEN)
DOWNLOAD_PATH=$(echo "$JOB_DATA" | jq -r '.[1]')
# 3. Pull the actual file directly using the exact path provided by the API
curl -s -k --output "${BACKUP_DIR}/${FILENAME}" "http://127.0.0.1${DOWNLOAD_PATH}"
# 4. Delete backups older than 30 days
find "${BACKUP_DIR}" -name "truenas-config-*.tar" -type f -mtime +30 -delete
- Make the script executable:
chmod +x /mnt/YOUR_POOL/system-backups/backup_config.sh
Step 2: Automate the Script via Cron Job
Schedule TrueNAS to execute this script automatically every day before sending the files offsite.
- Navigate to System > Advanced Settings >Cron Jobs and click Add.
- Description:
Generate Daily Config Backup Archive
- Command:
/mnt/YOUR_POOL/system-backups/backup_config.sh
- Run As User:
root
- Schedule: Set it to run daily (e.g., Every day at
02:00 AM).
- Click Save.
Step 3: Link Your S3 Bucket Credentials
Now, prepare TrueNAS to communicate securely with your S3 bucket. [1]
- Go to Credentials > Backup Credentials > Cloud Credentials and click Add.
- Name the credential (e.g.,
AWS-S3-Backup).
- Under Provider, select Amazon S3 (or generic S3 if using Wasabi, Backblaze B2, or MinIO).
- Paste your cloud account's Access Key ID and Secret Access Key.
- Click Verify to confirm the handshake with AWS is successful, then click Save
The final step uses TrueNAS's built-in replication tools to synchronize your backup folder to the cloud. [1]
- Navigate to Data Protection > Cloud Sync Tasks and click Add.
- Description:
Sync Config Backups to S3
- Direction: Select PUSH (this uploads data to the cloud).
- Transfer Mode: Select SYNC (mirrors your local folder; automatically handles remote file deletion when files age out locally).
- Directory/Files: Choose your local path:
/mnt/YOUR_POOL/system-backups.
- Credential: Select the
AWS-S3-Backup credential you created in Step 3.
- Bucket: Select your designated target S3 bucket from the auto-populated drop-down menu.
- Schedule: Set this to run daily, at least one hour after the local Cron Job (e.g., Every day at
03:00 AM).
- Click Save.
💡 Pro-Tip: S3 Bucket Security
Because TrueNAS configuration files contain your system's password hashes, API tokens, and private networking configurations, it is highly recommended to enable Server-Side Encryption (SSE-S3) and Bucket Versioning directly inside your AWS S3 Console. This adds a layer of defense against accidental deletion or ransomware targeting your NAS shares.