Backup (from command line)/Restore OpenFiler

Backup Openfiler

When I need a Openfiler backup for the first time, I did this:

1. Log in OpenFiler Web UI
2. Click System
3. Click Backup/Restore
4. Click Download

This works well if you have time to do this steps every day… but if you don’t want to do this steps every day, you must find another way to do daily backups…

After my little research, I find out that when I click on Backup/Restore, Openfiler cal this file: https://openfiler:446/admin/system_backup.html

I examined the content of this file and finded out, that all you need to backup your OpenFiler configuration is this:

export LANG=C; /usr/bin/sudo grep /mnt/ /etc/fstab > /opt/openfiler/etc/fstab_mnt
export LANG=C; /usr/bin/sudo /bin/tar --ignore-failed-read -cPpzf / --exclude /opt/openfiler/etc/httpd/logs --exclude /opt/openfiler/etc/update.log /opt/openfiler/etc/

After that, I created a script to put in my crontab, which backup Openfiler configuration every day. I keep only backups newer then 7 dasy, older backups are deleted.

Here is my script

BCKNAME="OpenFiler_`hostname`_`date "+%Y-%d-%m"`.tgz"
BCKFOLDER="/root/backup"
BCKCNT=`ls -1 $BCKFOLDER/OpenFiler_* | grep -c OpenFiler_`

function bck {
	export LANG=C; /usr/bin/sudo grep /mnt/ /etc/fstab > /opt/openfiler/etc/fstab_mnt
	export LANG=C; /usr/bin/sudo /bin/tar --ignore-failed-read -cPpzf $1 --exclude /opt/openfiler/etc/httpd/logs --exclude /opt/openfiler/etc/update.log /opt/openfiler/etc/
}

cd $BCKFOLDER

if [ $BCKCNT -gt 7 ];
then
	ls -tr -1 OpenFiler_*.tgz | tail -n 8 | head -n1 | xargs -I{} find $BCKFOLDER -name "OpenFiler_*.tgz" -not -newer {} | xargs rm
	bck $BCKFOLDER/$BCKNAME
else
	bck $BCKFOLDER/$BCKNAME
fi

How it works

This is a backup name (like OpenFiler_UrosOF_2012-21-02.tgz)

BCKNAME="OpenFiler_`hostname`_`date "+%Y-%d-%m"`.tgz"

Backup destination

BCKFOLDER="/root/backup"

This count backups already in backup folder

BCKCNT=`ls -1 $BCKFOLDER/OpenFiler_* | grep -c OpenFiler_`

Function to export all OpenFiler configuration files.
$1 -> function parameter: backup location/name

function bck {
	export LANG=C; /usr/bin/sudo grep /mnt/ /etc/fstab > /opt/openfiler/etc/fstab_mnt
	export LANG=C; /usr/bin/sudo /bin/tar --ignore-failed-read -cPpzf $1 --exclude /opt/openfiler/etc/httpd/logs --exclude /opt/openfiler/etc/update.log /opt/openfiler/etc/
}

Change directory to backup directory and check if backup folder contains more than 7 backups, if yes remove older backups and create a new one, else just create a new backup

cd $BCKFOLDER
if [ $BCKCNT -gt 7 ];
then
	ls -tr -1 OpenFiler_*.tgz | tail -n 8 | head -n1 | xargs -I{} find $BCKFOLDER -name "OpenFiler_*.tgz" -not -newer {} | xargs rm
	bck $BCKFOLDER/$BCKNAME
else
	bck $BCKFOLDER/$BCKNAME
fi

Restore Openfiler

1. Log in OpenFiler Web UI
2. Click System
3. Click Backup/Restore
4. Browse to your backup file
5. Click Upload

No Comments Yet.

Leave a Comment