Useful scripts

Status
Not open for further replies.

Rusky

Dabbler
Joined
Mar 26, 2013
Messages
42
I just setup a cron job to create nightly backups of my configuration, pretty handy.

Any other cool scripts you guys have come across that you'd care to share?
 

PhilipS

Contributor
Joined
May 10, 2016
Messages
179
I have a nightly cron job that backs up the configuration to a file with the date in the name. Over time this has naturally created a lot of redundant files, so I hacked together this bash script which will only backup the configuration if it is different than the newest file in the bkpfolder.

Code:
#!/bin/sh
bkpfolder='/mnt/tank/bkpconfig'

fc="`find $bkpfolder -maxdepth 1 -type f | wc -l | tr -d '[:space:]'`"
if [ $fc -eq 0 ]
then
  cp /data/freenas-v1.db $bkpfolder/`date +%Y%m%d`.db
else
  find $bkpfolder -maxdepth 1 -type f -exec stat -f "%m%t%N" {} + | sort | tail -1 | cut -f 2 | xargs cmp /data/freenas-v1.db
  if [ $? -ne 0 ]
  then
	cp /data/freenas-v1.db $bkpfolder/`date +%Y%m%d`.db
  fi
fi
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504

PhilipS

Contributor
Joined
May 10, 2016
Messages
179
...except that the system does this automatically for you, and has for a few releases now.

That's cool, where are these backups stored?
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
That's cool, where are these backups stored?
/var/db/system/configs-longhexnumber. On my system it's /var/db/system/configs-03dfc785c4b1491e8f0739ff94ed3f4b.
 
Status
Not open for further replies.
Top