Created
December 16, 2013 15:52
-
-
Save beezly/7989264 to your computer and use it in GitHub Desktop.
Backup Stingray Traffic Manager to a Git repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Replace the following variables for your environment | |
# zxtm - hostname of your Stingray Traffic Manager | |
# zxtmuser - username used to log in to Stingray SSH interface | |
# git_path - path to the git repo you want to store the config backups in | |
# | |
# I recommend that zxtmuser is able to log in to the Traffic Manager | |
# without using a password, using SSH keys. | |
# | |
# The script expectes that you have already created a git repository with | |
# a remote configured, as it does a git push at the end. You may want to | |
# change that behaviour if it doesn't suit you | |
zxtm=sr-live1 | |
zxtmuser=zxtmuser | |
git_path="/backups/stingray/${zxtm}" | |
mkdir -p "$git_path" | |
if [ ! -d "${git_path}/.git" ]; then | |
git init "${git_path}" | |
fi | |
tmp_dl_path=`mktemp -d -t sr-git-backup-XXXXX` | |
tmp_file=automated.tar | |
tmp_dl="${tmp_dl_path}/${tmp_file}" | |
tmp_compare_path=`mktemp -d -t sr-git-compare-XXXXX` | |
echo "Creating backup on ${zxtm}" | |
ssh -x "${zxtmuser}@${zxtm}" /opt/zeus/zxtm/bin/zcli << EOF | |
System.Backups.createBackup "automated", "Automated Backup" | |
System.Backups.downloadBackup "automated", "${tmp_file}" | |
EOF | |
echo "Downloading backup from ${zxtm} to ${tmp_dl}" | |
scp -q ${zxtmuser}@${zxtm}:${tmp_file} ${tmp_dl_path} | |
echo "Removing backup from ${zxtm}" | |
ssh -x "${zxtmuser}@${zxtm}" /opt/zeus/zxtm/bin/zcli << EOF | |
System.Backups.deleteBackups "automated" | |
EOF | |
ssh "${zxtmuser}@${zxtm}" rm automated.tar | |
echo "Extracting backup to ${tmp_compare_path}" | |
pushd "${tmp_compare_path}" >& /dev/null | |
tar xf "${tmp_dl}" | |
popd >& /dev/null | |
rm -f "${tmp_dl}" | |
rmdir "${tmp_dl_path}" | |
echo "Comparing backup against previous" | |
diff -ur "${git_path}/conf" "${tmp_compare_path}/conf" | |
if [ ! $? -eq 0 ]; then | |
echo "Backup differs from previous, updating... " | |
pushd "${git_path}" >& /dev/null | |
git rm -r . | |
cp -a "${tmp_compare_path}/conf" "${git_path}/" | |
git add -A | |
git commit -m 'Configuration Updated' | |
git push | |
popd >& /dev/null | |
echo "Committed" | |
exitcode=1 | |
else | |
echo "Backup matches, finished" | |
exitcode=0 | |
fi | |
rm -rf "${tmp_compare_path}" | |
exit $exitcode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cheers for sharing this Andy!