How to automate FreeNAS configuration database backup?

Status
Not open for further replies.

muwakasugi

Cadet
Joined
Jan 9, 2013
Messages
2
I'm using FreeNAS 8.3.0 p1, I have downloaded a FreeNAS configuration file via Web GUI, but how do you automate it?

I have tried cron and searched for "*.db" in the system, but still not sure what file I should backup.

Thanks.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
You can automate it however you want. I made a tutorial a few months ago that provides steps to automatically backup your config file nightly. I don't have the link handy, but try doing a quick search.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
This works for us.

Code:
#! /bin/sh -

# dumpconfig
#
# Create a volume named "config".  Use high compression and dedupe.
# Create a user named "configmgt" with a home of the volume and
# membership in "operator" group.  Place this shell script in the
# volume.  Set a cron job to run this frequently.  It will make a
# daily archive of the file for two months, then weekly after that.
# It is safe to run it multiple times a day, which has the effect
# of updating the day's configuration file with the most recent
# changes.
#
# This should be combined with rsync or replication to move the
# configuration somewhere so that a copy exists off of the machine
# in question.

# Copyright (C) 2011-2012 by sol.net Network Services.  All Rights
# Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.


set -e

fmt="`hostname`-`sed 's: .*::;s:FreeNAS-:freenas:;s:\.::g;s:-RELEASE:r:' /etc/version`"

# Hourly, daily filenames
hfn="${fmt}-`date +%Y%m%d.%H`.db"
dfn="${fmt}-`date +%Y%m%d`.db"

# Back it up
if [ -f /data/freenas-v1.db ]; then
        cp /data/freenas-v1.db "${HOME}/${hfn}"
        chmod 600 "${HOME}/${hfn}"
        rm -f "${HOME}/${dfn}"
        ln "${HOME}/${hfn}" "${HOME}/${dfn}"
fi

# Yesterday's hourly filenames, wipe them out
ofn="${fmt}-`date -j -v -1d +%Y%m%d.%H`.db"
if [ -f "${HOME}/${ofn}" ]; then
        rm "${HOME}/${ofn}"
fi

# Old daily filenames, wipe most of them
ofn="${fmt}-`date -j -v -2m +%Y%m%d`.db"
if [ -f "${HOME}/${ofn}" ]; then
        if [ `date +%w` -gt 0 ]; then
                rm "${HOME}/${ofn}"
        fi
fi

exit 0


As usual the code itself is trite. A more complex script that included cmp'ing versions was considered but deemed to be unnecessarily complicated, you don't necessarily want every revision in the config to be archived (but if you do this isn't the script for you). Space is cheap on a NAS especially if you can use dedupe. :smile:
 

muwakasugi

Cadet
Joined
Jan 9, 2013
Messages
2
Thanks, your script works perfect for me as well. Comparing the downloaded file to /data/freenas-v1.db with md5 hash, no difference between them, yay that's what I need!
Now I'll also try to dig the forum to find noobsauce80 thread :)
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Status
Not open for further replies.
Top