August 24, 2006 8:47 PM
mrtg working!
After struggling with mrtg trying to
get it up and running for a long time, I was just playing around
with it tonight, and finally .... cfgmaker worked! And this is the
cfgmaker line that works for me;-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cfgmaker --global 'WorkDir: /var/www/mrtg' --global 'Options[_]: bits,growright' --output /etc/mrtg/mrtg.cfg public@localhost
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ One less hassle now with the problem solved. :) -----
cfgmaker --global 'WorkDir: /var/www/mrtg' --global 'Options[_]: bits,growright' --output /etc/mrtg/mrtg.cfg public@localhost
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ One less hassle now with the problem solved. :) -----
August 18, 2006 2:14 PM
Backups
I've been using rsnapshot for backups
for some time now and becoming increasingly frustrated with it, in
that its weekly and monthly backup was very intermittent and didn't
fall into any regular pattern or work according to as specified in
the crontab. I've also been using flexbackup for my backups too,
but that is now too long in the tooth and unmaintained. So I've
been looking for a replacement backup program, and asked on the
Greater London Linux User Group irc channel [#gllug on freenode]
One of its members [Simon Morris, aka 'mozrat'] provided me with
the following code, which is saved as 'backup.sh' and obviously
executable and saved in your 'home' folder;-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
#
# backup.sh - Backup control script
# written by Simon Morris [aka mozrat] 12-08-2006.
# Usage: backup.sh LEVEL
#
# where LEVEL = 0, 1
# # Variables
EMAILTO="boztu@localhost"
DESTFILE="/mnt/winj/backup/backup.`date +%Y%m%d-%H%M`.`date +%a`.tar.bz2"
BACKUPFILES="/etc /home/boztu /opt/logwatch /var/www"
BACKUPDIR="${HOME}/backup"
LEVEL="${1}"
###############################################
##### DO NOT CHANGE BENEATH THIS LINE##########
###############################################
# Load backup functions
cd ${BACKUPDIR}
. backup-functions # Do some pre-flight work
pre_flight # Do the backup
tar_backup # Test the backup for errors
tar_verify # Email the backup report
mail_report # Done
exit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The variables are self-evident and can be tweaked to your needs. However, don't tweak it whilst your running a backup as it finishes one backup and then immediately starts one using your new code. And then there is the following code, which is saved in the 'backup' folder and called 'backup functions';-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This is not a shell script; it provides functions for the backup.sh script
# that sources it. # Variables
L0DATESTAMP="${BACKUPDIR}/.level0_datestamp"
NOW=`date` # Some pre-flight checks
pre_flight ()
{
dpkg -l > /root/backup/dpkg/dpkg.`date +%Y%m%d`.`date +%a`.txt
mysqldump --all-databases > /root/backup/mysql/mysql.`date +%Y%m%d`.`date +%a`.txt
for list in `list_lists -b`
do
config_list -o /root/backup/mailman/$list.`date +%Y%m%d`.`date +%a`.txt $list
list_members $list > /root/backup/mailman/$list.`date +%Y%m%d`.`date +%a`
-members.txt
done } # tar_backup function: does the archiving
tar_backup ()
{
echo "Level-${LEVEL} Backup ${NOW}"
if [ "${LEVEL}" = "0" ]; then
# make Level-0 datestamp
echo ${NOW} > ${L0DATESTAMP}
# Level-0 backup
tar --create --verbose \
--file ${DESTFILE} \
--blocking-factor 126 \
--label "Level-${LEVEL} Backup ${NOW}" \
--bzip2 \
${BACKUPFILES}
elif [ "${LEVEL}" = "1" ]; then
# get last Level-0 datestamp
LAST=`cat ${L0DATESTAMP}`
# Level-1 backup
tar --create --verbose \
--file ${DESTFILE} \
--blocking-factor 126 \
--after-date "${LAST}" \
--bzip2 \
--label "Level-${LEVEL} Backup from ${LAST} to ${NOW}" \
${BACKUPFILES}
else
# Backup level error
echo "Error: Level-${LEVEL} unknown"
exit
fi
echo "Level-${LEVEL} Backup END"
} # tar_verify function: test the archive for errors
tar_verify ()
{
echo "Level-${LEVEL} Backup Verify ${NOW}"
# Backup verify test
tar --list --verbose \
--file ${DESTFILE} \
--blocking-factor 126
echo "Level-${LEVEL} Backup Verify END"
} # mail_report function: sends backup report
mail_report ()
{
# Email backup report
mail -s "Level-${LEVEL} Backup" "${EMAILTO}" << EOF ###########################################################
Level-${LEVEL} Backup
########################################################### Host: ${HOSTNAME}
Files: ${BACKUPFILES} Destination: ${DESTFILE} ###########################################################
Started: ${NOW}
Completed: `date`
########################################################### `cat /tmp/cpfile.txt` EOF
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Then just set up crontab to call it whenever you want and it will do whatever you have called for in the variables in 'backup.sh'. Simple and works like a dream :) -----
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/sh
#
# backup.sh - Backup control script
# written by Simon Morris [aka mozrat] 12-08-2006.
# Usage: backup.sh LEVEL
#
# where LEVEL = 0, 1
# # Variables
EMAILTO="boztu@localhost"
DESTFILE="/mnt/winj/backup/backup.`date +%Y%m%d-%H%M`.`date +%a`.tar.bz2"
BACKUPFILES="/etc /home/boztu /opt/logwatch /var/www"
BACKUPDIR="${HOME}/backup"
LEVEL="${1}"
###############################################
##### DO NOT CHANGE BENEATH THIS LINE##########
###############################################
# Load backup functions
cd ${BACKUPDIR}
. backup-functions # Do some pre-flight work
pre_flight # Do the backup
tar_backup # Test the backup for errors
tar_verify # Email the backup report
mail_report # Done
exit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The variables are self-evident and can be tweaked to your needs. However, don't tweak it whilst your running a backup as it finishes one backup and then immediately starts one using your new code. And then there is the following code, which is saved in the 'backup' folder and called 'backup functions';-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# This is not a shell script; it provides functions for the backup.sh script
# that sources it. # Variables
L0DATESTAMP="${BACKUPDIR}/.level0_datestamp"
NOW=`date` # Some pre-flight checks
pre_flight ()
{
dpkg -l > /root/backup/dpkg/dpkg.`date +%Y%m%d`.`date +%a`.txt
mysqldump --all-databases > /root/backup/mysql/mysql.`date +%Y%m%d`.`date +%a`.txt
for list in `list_lists -b`
do
config_list -o /root/backup/mailman/$list.`date +%Y%m%d`.`date +%a`.txt $list
list_members $list > /root/backup/mailman/$list.`date +%Y%m%d`.`date +%a`
-members.txt
done } # tar_backup function: does the archiving
tar_backup ()
{
echo "Level-${LEVEL} Backup ${NOW}"
if [ "${LEVEL}" = "0" ]; then
# make Level-0 datestamp
echo ${NOW} > ${L0DATESTAMP}
# Level-0 backup
tar --create --verbose \
--file ${DESTFILE} \
--blocking-factor 126 \
--label "Level-${LEVEL} Backup ${NOW}" \
--bzip2 \
${BACKUPFILES}
elif [ "${LEVEL}" = "1" ]; then
# get last Level-0 datestamp
LAST=`cat ${L0DATESTAMP}`
# Level-1 backup
tar --create --verbose \
--file ${DESTFILE} \
--blocking-factor 126 \
--after-date "${LAST}" \
--bzip2 \
--label "Level-${LEVEL} Backup from ${LAST} to ${NOW}" \
${BACKUPFILES}
else
# Backup level error
echo "Error: Level-${LEVEL} unknown"
exit
fi
echo "Level-${LEVEL} Backup END"
} # tar_verify function: test the archive for errors
tar_verify ()
{
echo "Level-${LEVEL} Backup Verify ${NOW}"
# Backup verify test
tar --list --verbose \
--file ${DESTFILE} \
--blocking-factor 126
echo "Level-${LEVEL} Backup Verify END"
} # mail_report function: sends backup report
mail_report ()
{
# Email backup report
mail -s "Level-${LEVEL} Backup" "${EMAILTO}" << EOF ###########################################################
Level-${LEVEL} Backup
########################################################### Host: ${HOSTNAME}
Files: ${BACKUPFILES} Destination: ${DESTFILE} ###########################################################
Started: ${NOW}
Completed: `date`
########################################################### `cat /tmp/cpfile.txt` EOF
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Then just set up crontab to call it whenever you want and it will do whatever you have called for in the variables in 'backup.sh'. Simple and works like a dream :) -----