Guys,
I have the below script for taking some one shot backup. I can use either a ./backup-sys-config and ./archive
When i run them through ./ directly, it exactly works 100% okey. But then when I put those to crontab, then it works partially and yes!! a total mess. below are my crontab:
Code:
[mishu@ns1 backup]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
# Custom Cron jobs
#Every 15 minutes
0-59/15 * * * * admin /root/sysinfo
0-59/15 * * * * admin /root/update-awstats
#Every day
00 3 * * * admin /root/backup-sys-config
01 4 * * * admin /root/archive
#0 3 * * * admin /root/check-opl.pl
Below is my backup-sys-config:
Code:
#!/bin/bash
# Necessary veriables. Add catagory/major directory as a veriable. Just to make life more easier
documentRoot=/backup/operational
banners=$documentRoot/banners
awstats=$documentRoot/awstats
httpd=$documentRoot/httpd
named=$documentRoot/named
vsftpd=$documentRoot/vsftpd
etc=$documentRoot/etc
commands=$documentRoot/commands
# It is not related to backing up the conf and other files. But very important for the system.
echo "Killing all named processes..."
killall named
service named start
echo "DNS service started..."
# First removing the existing backup
echo "Starting of system conf file backup..."
#sleep 1 #This is for a little hault. U may omit it fully
echo " Removing existing backup..."
rm -rf $documentRoot/*
#sleep 1
echo " Backing up necessary files..."
mkdir $banners
cp /etc/banners/* $banners
echo " Banners has been backed up..."
mkdir $awstats
cp /etc/awstats/awstats.www.*.conf $awstats/
cp /usr/local/awstats/wwwroot/cgi-bin/awstats*.txt $awstats/
echo " Awstats has been backed up..."
mkdir $httpd
cp /etc/httpd/conf/httpd.conf $httpd/
mkdir $httpd/conf.d/
cp /etc/httpd/conf.d/* $httpd/conf.d/
echo " httpd conf files has been backed up..."
mkdir $named
mkdir $named/externals
mkdir $named/internals
cp /var/named/chroot/etc/named.conf $named/
cp /var/named/chroot/var/named/* $named/
cp /var/named/chroot/var/named/externals/* $named/externals/
cp /var/named/chroot/var/named/internals/* $named/internals/
echo " named conf files and zone files has been backed up..."
mkdir $vsftpd
cp /etc/vsftpd/vsftpd.conf $vsftpd/
echo " vsftpd conf and xinetd.d's vsftpd has been backed up..."
mkdir $etc
#cp /etc/modules.conf $etc/
#echo " modules.conf has been backed up."
cp /etc/shadow $etc/
echo " shadow has been backed up."
cp /etc/passwd $etc/
echo " passwd has been backed up."
cp /etc/group $etc/
echo " group has been backed up."
cp /etc/grub.conf $etc/
echo " grub.conf has been backed up."
cp /etc/hosts $etc/
echo " hosts file has been backed up."
cp /etc/resolv.conf $etc/
echo " resolv.conf has been backed up."
cp /etc/crontab $etc/
echo " crontab has been backed up."
echo " Backup of necessary files in /etc has been complete..."
#sleep 1
echo " Backing up custom commands under /root..."
mkdir $commands
cp /root/backup-* $commands
cp /root/flush* $commands
cp /root/firewall* $commands
cp /root/update-awstats $commands
cp /root/update-file-index $commands
cp /root/monitor* $commands
cp /root/archive* $commands
cp /root/grab-spoof-fuckers $commands
cp /root/sysinfo $commands
echo " Backup of custom commands under /root has been complete."
#sleep 1
and below is my archive
Code:
#!/bin/bash
# Some variables to make life more easier
WORK_DIR=/backup
BACKUP_DIR=$WORK_DIR/backup
CONF_FILE_BAK_DIR=$WORK_DIR/operational
BANNERS=$CONF_FILE_BAK_DIR/banners
AWSTATS=$CONF_FILE_BAK_DIR/awstats
HTTPD=$CONF_FILE_BAK_DIR/httpd
NAMED=$CONF_FILE_BAK_DIR/named
VSFTPD=$CONF_FILE_BAK_DIR/vsftpd
ETC=$CONF_FILE_BAK_DIR/etc
COMMANDS=$CONF_FILE_BAK_DIR/commands
echo "Starting of backup..."
sleep 1 # This is purely optional and used for a hault for one second.
# Taking a operational copy of all necessary conf files and passwords, etc.
echo " Taking the operational copies of all necessary system conf files, etc."
#sleep 1 # This is purely optional and used for a hault for one second.
# First removing the existing backup
echo " Removing existing conf backups."
rm -rf $CONF_FILE_BAK_DIR/*
echo " Done..."
echo " Removing existing database backups."
rm -rf $WORK_DIR/mysqlbackup.sql
echo " Done..."
# Now backup all the necessary conf files and other necessary system related files
echo " Backing up mysql databases..."
mysqldump -u dbuser -p dbuser -A -a --opt -v > $WORK_DIR/mysqlbackup.sql
echo " Backing up of mysql dataabse completed."
echo " Backing up necessary files..."
#sleep 1 # This is purely optional and used for a hault for one second.
mkdir $BANNERS
cp /etc/banners/* $BANNERS
echo " Banners have been backed up..."
mkdir $AWSTATS
cp /etc/awstats/awstats.www.*.conf $AWSTATS/
cp /usr/local/awstats/wwwroot/cgi-bin/awstats*.txt $AWSTATS/
echo " Awstats has been backed up..."
mkdir $HTTPD
cp /etc/httpd/conf/httpd.conf $HTTPD/
mkdir $HTTPD/conf.d/
cp /etc/httpd/conf.d/* $HTTPD/conf.d/
echo " httpd conf files has been backed up..."
mkdir $NAMED
mkdir $NAMED/externals
mkdir $NAMED/internals
cp /var/named/chroot/etc/named.conf $NAMED/
cp /var/named/chroot/var/named/* $NAMED/
cp /var/named/chroot/var/named/externals/* $NAMED/externals/
cp /var/named/chroot/var/named/internals/* $NAMED/internals/
echo " named conf files and zone files has been backed up..."
mkdir $VSFTPD
cp /etc/vsftpd/vsftpd.conf $VSFTPD/
echo " vsftpd conf and xinetd.d's vsftpd has been backed up..."
mkdir $ETC
cp /etc/modules.conf $ETC/
echo " modules.conf has been backed up."
cp /etc/shadow $ETC/
echo " shadow has been backed up."
cp /etc/passwd $ETC/
echo " passwd has been backed up."
cp /etc/group $ETC/
echo " group has been backed up."
cp /etc/grub.conf $ETC/
echo " grub.conf has been backed up."
cp /etc/hosts $ETC/
echo " hosts file has been backed up."
cp /etc/resolv.conf $ETC/
echo " resolv.conf has been backed up."
cp /etc/crontab $ETC/
echo " crontab has been backed up."
echo " Backing up custom commands under /root..."
#sleep 1 # This is purely optional and used for a hault for one second.
mkdir $COMMANDS
cp /root/backup-* $COMMANDS
cp /root/flush* $COMMANDS
cp /root/firewall* $COMMANDS
cp /root/update-awstats $COMMANDS
cp /root/update-file-index $COMMANDS
cp /root/monitor* $COMMANDS
cp /root/archive* $COMMANDS
cp /root/grab-spoof-fuckers $COMMANDS
cp /root/sysinfo $COMMANDS
echo " Backup of custom commands under /root has been complete."
echo " Taking the operational copies of all necessary system conf files, etc. have been done."
#sleep 1 # This is purely optional and used for a hault for one second.
# Check for previous unsuccessful backup. Remove if found.
#echo " Checking for any previous unsuccessful backups..."
#if
#[ -f $WORK_DIR/*.tar ] || [ -f $WORK_DIR/*.gz ]
#then
#echo " There is an unsucessful backup."
#sleep 1 # This is purely optional and used for a hault for one second.
# Removing any unsuccessful backups if any exists.
echo " Removing all the unsuccessful backups found/exists..."
rm -rf $WORK_DIR/*.tar
rm -rf $WORK_DIR/*.gz
echo " Done..."
#else
#echo " There is no unsuccessful backup."
#sleep 1 # This is purely optional and used for a hault for one second.
#fi
# Making the tar balls of the files/folders needed to be backed-up. Note: That
# you should not use it in verbose mode since it will work for the scheduled
# backup also. Also remember, do not use the command tar -zcv because -z is the
# parameter for compressing. But we'll do it later using gzip. So while extracting,
# we can simply go through the command tar -zxvf bla bla bla....
echo " Making the tarballs..."
tar -cvf $WORK_DIR/mysqlbackup.sql.tar $WORK_DIR/mysqlbackup.sql
tar -cvf $WORK_DIR/192.168.0.10.tar /var/www/192.168.0.10/
tar -cvf $WORK_DIR/www.parentdomain.org.tar /var/www/parentdomain.org/
tar -cvf $WORK_DIR/www.cdomain.com.tar /var/www/www.cdomain.com/
tar -cvf $WORK_DIR/www.bdomain.com.tar /var/www/www.bdomain.com/
tar -cvf $WORK_DIR/www.adomain.com.tar /var/www/www.adomain.com/
tar -cvf $WORK_DIR/www.opl.com.tar /var/www/www.opl.com/
tar -cvf $WORK_DIR/www.ns-hq.somedomain.org.tar /var/www/www.ns-hq.somedomain.org/
tar -cvf $WORK_DIR/dbserv.somedomain.org.tar /var/www/dbserv.somedomain.org/
tar -cvf $WORK_DIR/nsu-alumni.somedomain.org.tar /var/www/nsu-alumni.somedomain.org/
tar -cvf $WORK_DIR/nsucpds.somedomain.org.tar /var/www/nsucpds.somedomain.org/
tar -cvf $WORK_DIR/mysqldb.tar /var/lib/mysql/
tar -cvf $WORK_DIR/conf-origi.bak.tar /backup/original/
tar -cvf $WORK_DIR/conf-oper.bak.tar /backup/operational/
tar -cvf $WORK_DIR/root.tar /root/
echo " Done..."
# Compressing the tar balls. -9 is for best compression.
echo " Compressing the tarballs to gzip"
gzip -9v $WORK_DIR/*.tar
echo " Done..."
# Removing the existing backup and creating a new folder for the new backup in the /backup drive.
echo " Removing the existing backup and creating new folder for the backup in the /backup drive..."
rm -rf $BACKUP_DIR
mkdir $BACKUP_DIR
# Moving the backup files to the backup folder from the working folder.
echo " Moving the backup files to the backup folder from the working folder..."
mv $WORK_DIR/*.tar.gz $BACKUP_DIR
echo " Done..."
# Deleting leftover files if any.
echo " Deleting leftover files if any..."
rm -rf $WORK_DIR/*.sql
rm -rf $WORK_DIR/*.tmp
echo " Done..."
echo "Backup job has been complete!!"
Any ideas?? I'm using CENTOS 5.6...