Backing Up Your Zones
Posted: Fri Aug 13, 2004 5:27 am
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.
Floyd
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