- PowerShell 100%
| .gitignore | ||
| Get-TrueNAS-Backup-WS.ps1 | ||
| Get-TrueNAS-Backup.ps1 | ||
| LICENSE | ||
| README.md | ||
| SECURITY.md | ||
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
- PowerShell v7.x
- API key from your TrueNAS deployment
- SSL/TLS must be configured on your TrueNAS system or your API key gets automatically revoked when you use it
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
- Open the script in your favorite text editor and change the default configuration between
# START - Script Configurationand# END - Script Configuration
Generate an API key
- Login to your TrueNAS web interface
- Click 'Credentials' and 'Users'
- Click 'Api Keys'
- Click 'Add'
- Give the key a meaningful name, set the username to 'truenas_admin', leave 'Non-expiring' checked and click 'Save'
- Add the API key to your password vault or some place secure, you can't view it again after you click 'Close'
- 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.
- Launch PowerShell v7.x
- Change to the directory where you cloned the script
- Run the script
.\Get-TrueNAS-Backup-WS.ps1 -TrueNASFQDN <FQDN OF YOUR TRUENAS> - Enter the API key when prompted
- Check that the
LogsandBackupsdirectories were created and that there is a log file inLogsand a tar file inBackups
Schedule the job
- Click 'Start' and type "task" and click 'Task Scheduler'
- Click 'Task Scheduler Library'
- Right click the white space in the middle of the screen and choose 'Create New Task'
- 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
- Go to the 'Triggers' tab and click 'New'
- Setup a schedule for how often you want to backup your TrueNAS and click 'Ok'
- Go to the 'Actions' tab and click 'New'
- Set 'Program/script' to
"C:\Program Files\PowerShell\7\pwsh.exe"(with the quotes) - Set 'Add arguments (optional)' to
<PATH TO THE SCRIPT>\Get-TrueNAS-Backup-WS.ps1 -TrueNASFQDN <FQDN OF YOUR TRUENAS> - Click 'Ok'
- Click 'Ok' and enter the password for the user account you're running the task under
- Right click the task you just created and choose 'Run' and verify everything works