Backing up TrueNAS Scale configuration using SSH

When backing up TrueNAS using the Web GUI, you are provided a .tar archive containing freenas-v1.db as well as pwenc_secret if you chose to back up the system seed. While there is no easy way to automate a configuration backup using the Web GUI, you can achieve the same goal using SSH.

Optional prerequisite: Configure SSH public key authentication to automate backups

  • Log into TrueNAS Web GUI
  • Go to Credentials > Local Users > root
  • Click Edit
  • Go to the Authorized Keys section and paste the contents from the system you using to back up TrueNAS.

Now from the system you are using to back up TrueNAS you can run the following:

1$ ssh root@[TrueNAS IP] "mkdir /tmp/backup ; sqlite3 /data/freenas-v1.db '.timeout 10000' '.backup /tmp/backup/freenas-v1.db' ; tar -cf - -C /data pwenc_secret -C /tmp/backup freenas-v1.db ; rm -rf /tmp/backup" > TrueNAS_Backup.tar

This file will contain passwords and the system seed so you should ensure you protect it and optionally store it inside an encrypted container (ie. an encrypted 7zip file).

Remember to test your backup/restore strategy before a disaster happens!