No description
  • PowerShell 100%
Find a file
2026-03-14 19:35:35 -07:00
.gitignore Updated README and script for new WebSocket API support in TrueNAS 25.04 and later. 2026-01-18 13:53:43 -08:00
Get-TrueNAS-Backup-WS.ps1 Updated README and script for new WebSocket API support in TrueNAS 25.04 and later. 2026-01-18 13:53:43 -08:00
Get-TrueNAS-Backup.ps1 Updated README and script for new WebSocket API support in TrueNAS 25.04 and later. 2026-01-18 13:53:43 -08:00
LICENSE Update LICENSE 2026-02-06 14:15:35 -08:00
README.md Update README.md 2026-01-24 20:53:55 -08:00
SECURITY.md Update SECURITY.md 2026-03-14 19:35:35 -07:00

TrueNAS Backup Script

A method to backup your TrueNAS configuration to a remote location.

There are two versions of this script as of 2026-01-18:

  • Get-TrueNAS-Backup.ps1 - Original script, works with the soon to be deprecated REST API (TrueNAS 25.10 and older)
  • Get-TrueNAS-Backup-WS.ps1 - New script, works with the modern WebSockets API (TrueNAS 25.04 and newer)

Using and configuring the scripts is the exact same.

Original blog post: Automated TrueNAS Configuration Backups

AI Disclosure

The original script (Get-TrueNAS-Backup.ps1) was mostly written by me with the assistance of CoPilot mostly for code completion. Testing was done by me.

The updated script (Get-TrueNAS-Backup-WS.ps1) was completely updated by Claude AI and tested by me.

Requirements

Installation

Clone the repository to your local machine

git clone https://git.pickysysadmin.ca/eric/truenas-config-backup.git
cd truenas-config-backup

OR

Download the latest version from the releases page and extract it

Configuration

Note: If you are using TrueNAS 24.10 and older use Get-TrueNAS-Backup.ps1 instead of Get-TrueNAS-Backup-WS.ps1

  1. Open the script in your favorite text editor and change the default configuration between # START - Script Configuration and # END - Script Configuration

Generate an API key

  1. Login to your TrueNAS web interface
  2. Click 'Credentials' and 'Users'
  3. Click 'Api Keys'
  4. Click 'Add'
  5. Give the key a meaningful name, set the username to 'truenas_admin', leave 'Non-expiring' checked and click 'Save'
  6. Add the API key to your password vault or some place secure, you can't view it again after you click 'Close'
  7. Click 'Close'

Test run

Note: You want to do this as the user you are going to run the scheduled task under. When the Credentials.xml is created after you enter your API Key it is bound to the user running the script at the time. If you do your test run as foo and then schedule your task as bar, bar won't have access to the Credentials.xml.

  1. Launch PowerShell v7.x
  2. Change to the directory where you cloned the script
  3. Run the script .\Get-TrueNAS-Backup-WS.ps1 -TrueNASFQDN <FQDN OF YOUR TRUENAS>
  4. Enter the API key when prompted
  5. Check that the Logs and Backups directories were created and that there is a log file in Logs and a tar file in Backups

Schedule the job

  1. Click 'Start' and type "task" and click 'Task Scheduler'
  2. Click 'Task Scheduler Library'
  3. Right click the white space in the middle of the screen and choose 'Create New Task'
  4. Give the job a 'Name', select 'Run whether user is logged on or not'
    • Note: I recommend changing the user here to a sevice account or a group managed service account for production
  5. Go to the 'Triggers' tab and click 'New'
  6. Setup a schedule for how often you want to backup your TrueNAS and click 'Ok'
  7. Go to the 'Actions' tab and click 'New'
  8. Set 'Program/script' to "C:\Program Files\PowerShell\7\pwsh.exe" (with the quotes)
  9. Set 'Add arguments (optional)' to <PATH TO THE SCRIPT>\Get-TrueNAS-Backup-WS.ps1 -TrueNASFQDN <FQDN OF YOUR TRUENAS>
  10. Click 'Ok'
  11. Click 'Ok' and enter the password for the user account you're running the task under
  12. Right click the task you just created and choose 'Run' and verify everything works