Backing Up Your Zones

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
User avatar
floyd_2
Posts: 13
Joined: Thu Jul 22, 2004 1:34 am

Backing Up Your Zones

Post by floyd_2 »

I started getting paranoid that I might have a disk crash and that I'd lose all of my zone settings. To this end, I wrote a small script (and cronned it) that produces a formatted Zone report so that all zones could be reconstructed if I had a disk crash (I know...why dont I just do backups/exports to other media). After the report is produced, it ftps it to the web area provided by my ISP. Anyway...for what it's worth...here's the script. Just modify the parms to suit yourself. Dont forget to create your $HOME/.netrc. There may be more secure ways of automating the FTP, but this was the easiest.

Code: Select all

#!/bin/bash
#
# Create a list of Zones for all monitors in /tmp and FTP it to the web
#  for safe keeping
#
# Prerequisite:  Create $HOME/.netrc, permissions 600 as follows:
#
#                  machine [insert your webspace upload area here]
#                  login [insert login name here]
#                  password [insert password here]
#
# Example $HOME/.netrc follows:
#
#                  machine users.isp.com
#                  login george
#                  password ofthejungle
#
# $HOME/.netrc is used for the ftp at the bottom of the script
# 
# Thanks for helping me with the SQL Nugget.
#
#  Floyd  13/8/2004

# Your ZM database name
database="[your zm database - probably zm]"

# Your ROOT DB username
rootdb="[username - probably root]"

# Your ROOT DB password
rootpass="[password]"

# Location of local output file
outputlocal="/tmp/Zones.txt"

# Output filename on Webserver
outputweb="Zones.txt"

# Name of Website to FTP to
website="[insert your webspace upload area here]"

# Initialise Local output file
echo "`date`" > $outputlocal

# Run mysql command to extract a callated set of info from the DB to output file
mysql -t -D $database -u "$rootdb" --password="$rootpass" << EOF >> $outputlocal
   select M.Name, Z.* from Zones Z
   left join Monitors M on Z.MonitorId=M.ID order by Z.MonitorId;
EOF

# Now lets ftp our file to the internet for safe keeping
ftp -v $website << EOF
   ascii
   put $outputlocal $outputweb
   quit
EOF
Floyd
Post Reply