Updated 2026-01-18
With the upcoming deprecation of the TrueNAS REST API in TrueNAS 26.04 I’ve released a v1.1 which includes a second script called “Get-TrueNAS-Backup-WS.ps1“. This second script works with the new WebSocket API introduced in TrueNAS 25.04.
Original post (2025-05-06) below:
I recently moved to TrueNAS in my Homelab and was a bit frustrated to find there wasn’t really a build-in method for backing up your configuration files and keys to storage located external to TrueNAS.
I tried setting up some basic rsync jobs to get the contents off my TrueNAS and over to my backup server but ended up giving up in frustration. I suspect this has more to do with my destination being a Windows Server running Veeam than anything on TrueNAS itself.
Then I found the TrueNAS API and saw it allows for creating backups so with the help of CoPilot I whipped up a quick script I can schedule on my Backup Server to grab a config backup from TrueNAS nightly.
The source and installation instructions can be found here: https://git.pickysysadmin.ca/eric/truenas-config-backup
Sample output:
PS D:\Backup-TrueNAS> .\Get-TrueNAS-Backup.ps1 -TrueNASFQDN myTrueNas.local
2025-05-06 18:46:04 - INFO: Logs directory already exists.
Transcript started, output file is D:\Backup-TrueNAS\Logs\TrueNAS-Backup-2025-05-06_18-46-04.log
Enter the TrueNAS API key: ******************************************************************
2025-05-06 18:46:16 - SUCCESS: Credentials.xml file created successfully.
2025-05-06 18:46:16 - INFO: Backups directory already exists.
2025-05-06 18:46:16 - DEBUG: Response headers:
StatusCode : 200
StatusDescription : OK
Content : {46, 47, 46, 47…}
RawContent : HTTP/1.1 200 OK
Server: nginx
Date: Wed, 07 May 2025 01:46:16 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
X-Cont…
Headers : {[Server, System.String[]], [Date, System.String[]], [Transfer-Encoding, System.String[]], [Connection, System.String[]]…}
RawContentLength : 839680
RelationLink : {}
2025-05-06 18:46:17 - SUCCESS: Backup completed successfully.
Transcript stopped, output file is D:\Backup-TrueNAS\Logs\TrueNAS-Backup-2025-05-06_18-46-04.log
PS D:\Backup-TrueNAS>
and a quick check to see if the backup was saved:
PS D:\Backup-TrueNAS> dir .\Backups\
Directory: D:\Backup-TrueNAS\Backups
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 2025-05-06 6:46 PM 839680 TrueNAS-Backup-2025-05-06_18-46-16.tar
PS D:\Backup-TrueNAS>
I’m trying to do something similar but gave up trying to do it from Windows – I thought it may be easier to just have it all happen on the truenas system. I created the API token, created a dataset for the recovery file, typed up a bash script to run curl and pull the save file and drop it into the dataset, then I configured the cloud drive sync tasks to push sync from that dataset to the cloud. I used a cron job to automate the save file once a month and sync to the cloud once a week. This might be more steps but other than me dropping the script into a folder, I did everything in the gui and it’s all self contained while also backing up the script and the config to make it all happen.
Found your post while searching for ideas.
That’s funny. That is exactly the path I started down and gave up on because I wanted to keep my TrueNAS install as vanilla as possible to avoid some future update failing/breaking on me.
One of the great things I love about TrueNAS, there are lots of ways to accomplish a goal. I’m glad your method is working for you and thanks for posting an alternative.
awesome