Skip to content

Instantly share code, notes, and snippets.

@voodoojello
Created May 4, 2014 04:07
Show Gist options
  • Save voodoojello/f4fac70165d23cf10e46 to your computer and use it in GitHub Desktop.
Save voodoojello/f4fac70165d23cf10e46 to your computer and use it in GitHub Desktop.
This script will create a datestamped LZMA2 tarball of the current NxFilter state suitable for long-term backups, disaster recovery, or software upgrades.
#!/bin/sh
#
# NxFilter Stateful Backup
# Mark Page [m.e.page_at_gmail.com]
# modified: Sat May 3 07:40:51 CDT 2014
#
# This script will create a datestamped LZMA2 tarball
# of the current NxFilter state suitable for long-term
# backups, disaster recovery, or software upgrades.
#
# Note: This script requires that the NxFilter service
# be controlled through upstart, systemd, or SysV init.
#
if [ "$(id -u)" != "0" ]; then
echo "\n ERROR! This script must be run as root.\n" 1>&2
exit 1
fi
#
# Location of NxFilter installation, backup destination,
# and logging options. Change as needed.
#
export NX_HOME=/opt/nxfilter
export NX_BU_HOME=/var/nxfilter-backup
export NX_BU_LOG=/var/log/nx-backup-state.log
TIMESTAMP=$(date -d "today" +"%Y%m%d%H%M")
echo "Checking Directory Structures..."
if [ ! -d "$NX_BU_HOME" ]; then
echo " - Creating backup destination: $NX_BU_HOME..."
mkdir $NX_BU_HOME
fi
if [ ! -f "$NX_HOME/nxd.jar" ]; then
echo "\n ERROR! NxFilter environment not found at \"$NX_HOME\"!"
echo "\n - Set the NX_HOME var for this script to NxFilter's application directory and try again.\n"
exit 1
fi
echo "Stopping NxFilter Sevice..."
service nxfilter stop
sleep 5
#
# We're using LZMA2 for compression (faster and
# tighter IMHO), but this could easily be changed
# to gzip if one wished to sacrifice space for speed
# on less capable systems.
#
echo "Starting Backup..."
echo " - Backup progess writing to: $NX_BU_LOG"
XZ_OPT=-9 tar -JPcvf $NX_BU_HOME/nxfilter-$TIMESTAMP.tar.xz $NX_HOME > $NX_BU_LOG
echo "Re-Starting NxFilter Service..."
service nxfilter start
echo "Done.\n"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment