LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-18-2013, 10:42 PM   #1
aq_mishu
Member
 
Registered: Sep 2005
Location: Bangladesh
Distribution: RH 7.2, 8, 9, Fedora
Posts: 217

Rep: Reputation: 30
strange CRON problem


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...
 
Old 06-19-2013, 01:47 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by aq_mishu View Post
I'm using CENTOS 5.6...
Not good. They're at Update 9 nowadays. Please keep up to date.


Quote:
Originally Posted by aq_mishu View Post
(..) it works partially (..)
Partially how? Explain. And did you check /var/log/cron and (whichever unprivileged user account that receives root) email for cron messages?
 
Old 06-19-2013, 10:12 AM   #3
aq_mishu
Member
 
Registered: Sep 2005
Location: Bangladesh
Distribution: RH 7.2, 8, 9, Fedora
Posts: 217

Original Poster
Rep: Reputation: 30
planning on server upgrade, but that's a real big job at this place where i work.


The account has permission. Even I tried with root. no work.

Partially means it copies some of the files I have checked for the script for any mistake... but did not found any. And as said, when I run it manually, it does it fully. when via cron, it just say makes the sql and then it copies 3 folders and then it leaves rest.

I'll check on a fresh cronlog and will post soon.

Mishu~
 
Old 06-20-2013, 02:49 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
killall named

# should be 
service named stop   # much safer
Try adding
Code:
set -xv
near the top of your scripts and capture the outputs.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Cron directories: /var/spool/cron/cron.GfqqGO Woodsman Slackware 4 05-11-2011 02:37 PM
[SOLVED] Strange message from cron Hosferatu Linux - General 2 01-28-2011 02:51 PM
Strange solution for problem with cron-sheduling dzcharles Programming 17 05-13-2009 01:30 PM
Strange Cron problem (!?) monk5854 Red Hat 1 11-19-2007 03:17 PM
Strange cron errors 0p3r4 Linux - General 2 03-02-2006 09:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration