Here is a script to email your FreeNAS database backup

Status
Not open for further replies.

snickasaurus

Dabbler
Joined
Feb 19, 2012
Messages
18
Hello all. I've been playing around with my commandlinefu to keep it strong. There are definitely some great scripts out here to keep an eye on one's FreeNAS box. I just wanted to share this one in hopes someone might like it or a scripting/security guru could tell me how dumb of an idea it is.

First and foremost this requires adding biabam to your FreeNAS install. If you don't like adding tools to your FreeNAS then please disregard this post!

To add biabam, get to a root shell on FreeNAS and do the following:

For FreeNAS based on FreeBSD 10

Code:
wget http://pkg.freebsd.org/FreeBSD:10:amd64/latest/All/biabam-0.9.7_2.txz
pkg install biabam-0.9.7_2.txz
rehash


For FreeNAS based on FreeBSD 11 (untested as I'm still on FreeNAS-9.10.2-U6)
Code:
wget http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/biabam-0.9.7_2.txz
pkg install biabam-0.9.7_2.txz
rehash


The tool will be located in /usr/local/bin. Now on to the script. I have my running as a cron job every other day.

Code:
#!/bin/sh

logfile="/tmp/email-config-backup.log"

if [ "$(sqlite3 /data/freenas-v1.db "pragma integrity_check;")" = "ok" ]
then
### Send config backup ###
	mkdir /tmp/backupConfig
	cd /tmp/backupConfig || return
	cp /data/freenas-v1.db /tmp/backupConfig/
	md5 freenas-v1.db > freenas-v1.md5
	sha256 freenas-v1.db > freenas-v1.sha256
	tar -cf config.tar ./freenas-v1.db ./freenas-v1.md5 ./freenas-v1.sha256
	mv config.tar FreeNASDatabase.tar
# Edit here to your liking
	echo "See attached .TAR file." | /usr/local/bin/biabam FreeNASDatabase.tar -s "FreeNAS Database Backup" YOUREMAILADDRESS
	cd -
	rm -R /tmp/backupConfig
else



LtNF8ni.png


JlouWxn.png
 
Last edited:

m0nkey_

MVP
Joined
Oct 27, 2015
Messages
2,739
I like the idea.

There is one thing I would recommend against; Installing a package.

Keep in mind that FreeNAS is an appliance OS. There is a high chance of losing changes at reboot or update.

If you could re-work it to use what's available, such as mail and uuencode commands, it would be resource worthy :)
 

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080
Hello all. I've been playing around with my commandlinefu to keep it strong. There are definitely some great scripts out here to keep an eye on one's FreeNAS box. I just wanted to share this one in hopes someone might like it or a scripting/security guru could tell me how dumb of an idea it is.

First and foremost this requires adding biabam to your FreeNAS install. If you don't like adding tools to your FreeNAS then please disregard this post!

To add biabam, get to a root shell on FreeNAS and do the following:

For FreeNAS based on FreeBSD 10

Code:
wget http://pkg.freebsd.org/FreeBSD:10:amd64/latest/All/biabam-0.9.7_2.txz
pkg install biabam-0.9.7_2.txz
rehash


For FreeNAS based on FreeBSD 11 (untested as I'm still on FreeNAS-9.10.2-U6)
Code:
wget http://pkg.freebsd.org/FreeBSD:11:amd64/latest/All/biabam-0.9.7_2.txz
pkg install biabam-0.9.7_2.txz
rehash


The tool will be located in /usr/local/bin. Now on to the script. I have my running as a cron job every other day.

Code:
#!/bin/sh

logfile="/tmp/email-config-backup.log"

if [ "$(sqlite3 /data/freenas-v1.db "pragma integrity_check;")" = "ok" ]
then
### Send config backup ###
	mkdir /tmp/backupConfig
	cd /tmp/backupConfig || return
	cp /data/freenas-v1.db /tmp/backupConfig/
	md5 freenas-v1.db > freenas-v1.md5
	sha256 freenas-v1.db > freenas-v1.sha256
	tar -cf config.tar ./freenas-v1.db ./freenas-v1.md5 ./freenas-v1.sha256
	mv config.tar FreeNASDatabase.tar
# Edit here to your liking
	echo "See attached .TAR file." | /usr/local/bin/biabam FreeNASDatabase.tar -s "FreeNAS Database Backup" YOUREMAILADDRESS
	cd -
	rm -R /tmp/backupConfig
else



LtNF8ni.png


JlouWxn.png
Did I have a time warp? We have a script for this already.

Sent from my SAMSUNG-SGH-I537 using Tapatalk
 

snickasaurus

Dabbler
Joined
Feb 19, 2012
Messages
18
I like the idea.
If you could re-work it to use what's available, such as mail and uuencode commands, it would be resource worthy :)

I had issues with uuencode but I'll have a look at the mail command. Thanks for the input m0nkey_
 

snickasaurus

Dabbler
Joined
Feb 19, 2012
Messages
18
Did I have a time warp? We have a script for this already.

Sent from my SAMSUNG-SGH-I537 using Tapatalk

Did I fail at searching? Because I didn't find one. There are scripts to check the integrity of the config, scripts to report temp status and scripts to copy the database to local storage. I have not found one that will compress and email it. Either way...great reply.
 
Last edited:

Chris Moore

Hall of Famer
Joined
May 2, 2015
Messages
10,080

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
Consider too that the config file contains, potentially, authentication credentials for a number of services. At a minimum, it will have usernames and passwords for your FreeNAS server itself, but it may also have a lot of other sensitive stuff. You may not want to send it out onto an insecure network.
 
Status
Not open for further replies.
Top