Best way to get auto config backup?

HarambeLives

Contributor
Joined
Jul 19, 2021
Messages
153
You guys have steered me right so far, I'm hoping you can do it again

Is there a BEST way to get auto config backup? Ideally just to a file on my NAS. I have the system dataset moved to the boot pool so I can do passphrase encryption

I have seen the email backup script, but I would rather just have it as a file, and not an email
 

Kris Moore

SVP of Engineering
Administrator
Moderator
iXsystems
Joined
Nov 12, 2015
Messages
1,471
If you want to spin up an instance of TrueCommand (locally or in the cloud) it does this for your automatically. It monitors your config file for changes and takes backups of it automatically, which you can download via the TC WebUI in case you lose the TrueNAS boot device catastrophically.
 

HarambeLives

Contributor
Joined
Jul 19, 2021
Messages
153
Wow! I had no idea. That sounds pretty cool
 

etnica

Dabbler
Joined
Aug 2, 2021
Messages
13
Is there any REST API endpoint where you could get it from ?(couldn't find it myself when checking API doc)
So you could fetch it via a http request(curl)?
 

HarambeLives

Contributor
Joined
Jul 19, 2021
Messages
153
If you want to spin up an instance of TrueCommand (locally or in the cloud) it does this for your automatically. It monitors your config file for changes and takes backups of it automatically, which you can download via the TC WebUI in case you lose the TrueNAS boot device catastrophically.

Is there any way to get the config backup to save to the data directory?

In the notes for the container is:

Where the “[hostdirectory]” should point to some persistent directory on the host to use as the long-lived data directory for the container.

I went ahead and set this, however there is nothing in the folder. And when I make a config backup, nothing appears either. Just wondering if that folder is used at all, I would have assumed something would have made its way in there
 

HarambeLives

Contributor
Joined
Jul 19, 2021
Messages
153
Having a hard time figuring out how to get it to do Automatic configs, is this something that happens on some kind of schedule?

No information in the settings page, just that its set to keep 7. I did some manually as a test which worked (No idea where they are stored though)

I changed some settings on one of my boxes to see if it would save the config, and no new backups showed. Does it take some time?
 

NasKar

Guru
Joined
Jan 8, 2016
Messages
739
I use this script to back up the config and run it as a cron job daily. Set the 2 variables at the top of the script.
Code:
#
# Set these Variables - location of backup files and max number of files to keep #backuploc="/mnt/v1/configbackup"
backuploc="/mnt/v1/backup/config"
maxnrOfFiles=3

#
# Create directory for freenas version and backupname versiondir=`cat /etc/version | cut -d' ' -f1` backupname=`date \+%Y\%m\%d`_`cat /etc/version | cut -d' ' -f1`.db echo "Directory to put config in ${versiondir}"
echo "Name of backup file ${backupname}"
mkdir -p $backuploc/$versiondir

#
# Copy config file and rename
cp /data/freenas-v1.db ${backuploc}/${versiondir}/${backupname}
echo "cp /data/freenas-v1.db ${backuploc}/${backupname}"

#
# Delete old backups
#
# initallize variables
nrOfFiles=0

backupMainDir="${backuploc}/${versiondir}"
echo "Number of files to keep ${maxnrOfFiles}"
if [ ${maxnrOfFiles} -ne 0 ]
then
     echo "maxnrOfFiles is not 0"
     nrOfFiles="$(ls -l ${backupMainDir} | grep -c "^-.*")"
     echo "nrOfFiles=" $nrOfFiles
     nFileToRemove="$((nrOfFiles - maxnrOfFiles))"
     echo "nFileToRemove=" $nFileToRemove while [ $nFileToRemove -gt 0 ] do
     echo
     echo "number files to remove=" $nFileToRemove
     fileToRemove="$(ls -t ${backupMainDir} | tail -1)"
     echo "Removing file ${fileToRemove}"
     nFileToRemove="$((nFileToRemove - 1))"
     rm ${backupMainDir}/${fileToRemove} done fi






echo "done"
 
Joined
Jun 2, 2019
Messages
591
A simple BASH script running as a CRON is all you need.

Just make sure to add execute permissions (chmod a+x {filename})

It's doesn't currently backup the secret seed.

Code:
#!/bin/sh

FILENAME="`hostname -s`-`cut -d' ' -f1 /etc/version`-`date +%Y%m%d`.db"

#echo $FILENAME

cp /data/freenas-v1.db /mnt/data/truenas/$FILENAME

echo "Backup $FILENAME created"

find /mnt/data/truenas/NAS-?-TrueNAS-*.db -mtime +365 -exec rm {} \;
 

HarambeLives

Contributor
Joined
Jul 19, 2021
Messages
153
Thanks for the scripts guys, thats probably the best way

The TrueCommand looks cool, but so far I can only get it to save 1 config? I have it set to save 7 which is default, but all I get is the last

Here is one it made

1628193795203.png


Just checked now, and there is still one, but its later

1628193807541.png


And the directory I set for data is still completely empty
 

engedics

Cadet
Joined
Feb 5, 2023
Messages
1
Sorry for necroposting, but this is the first thread coming up when searching for automatic backup on SCALE. I've found this to be the easiest by using the API and a cron job. A folder and an API key has to be created first (API key: profile button on top right -> API Keys).
Secret seed export is optional, just change to false if not required.

curl --no-progress-meter \
-X 'POST' \
'<URL>/api/v2.0/config/save' \
-H 'Authorization: Bearer <API key>' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{"secretseed": true}' \
--output <folder>/$(hostname)-TrueNAS-$(date +%Y%m%d%H%M%S).tar
 
Top