LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Tar Won't Properly Backup FS From Cron (http://www.linuxquestions.org/questions/linux-software-2/tar-wont-properly-backup-fs-from-cron-873914/)

wafflesausage 04-09-2011 01:39 AM

Tar Won't Properly Backup FS From Cron
 
I've been having issues with cron and a backup script that I've been using. Here is the script below

Code:

#!/bin/sh
################################################################################
###### Variables ######

time=$(date +%Y%m%d)

numFiles=$(ls /backup/system/FreeLSD | wc -l)

launchBackup=$(exec tar -cvjf /backup/system/FreeLSD/$time.FreeLSD.systembackup.tar.bz2 --exclude=/backup --exclude=/proc --exclude=/tmp --exclude=/ftp --exclude=/mnt /)

oldestBackup=$(ls /backup/system/FreeLSD | sort -n | head -1)
################################################################################
###### Action! ######
if [ $numFiles -gt 2 ] ; then
rm /backup/system/FreeLSD/$oldestBackup
        else
exec $launchBackup && du -m /backup/system/FreeLSD/* | mail -s AutoBackup example@foomail.com
fi

And here is the entry of the offending script in my crontab
Code:


################################################################################
#minute        hour        mday        month        wday        who        command
################################################################################

#Automatically backs up the local filesystem into the backups directory with tar
23        1        *        *        *        root        /root/scripts/autobackup.sh

The script does run at the specified time and seems to function except for the fact that when it's run from cron, it only backs up approximately 130 MB of data. When it is run from a shell it performs the full backup. Here's a comparison of the script, the ones with the larger value were run from the shell, and the smaller ones were run by cron.
Code:

143        /backup/system/FreeLSD/20110404.FreeLSD.systembackup.tar.bz2
10686        /backup/system/FreeLSD/20110405.FreeLSD.systembackup.tar.bz2
68        /backup/system/FreeLSD/20110409.FreeLSD.systembackup.tar.bz2

Any ideas as to why this is happening?

Snark1994 04-09-2011 04:34 AM

Perhaps you could redirect the output of your 'tar' command to a file, so you can see what it's trying to do? You've already got the -v flag set on it...

wafflesausage 04-09-2011 04:50 AM

Quote:

Originally Posted by Snark1994 (Post 4318930)
Perhaps you could redirect the output of your 'tar' command to a file, so you can see what it's trying to do? You've already got the -v flag set on it...

I already tried appending it to the line where I defined $launchBackup like this
Code:

launchBackup=$(exec tar -cvjf /backup/system/FreeLSD/$time.FreeLSD.systembackup.tar.bz2 --exclude=/backup --exclude=/proc --exclude=/tmp --exclude=/ftp --exclude=/mnt / > /var/log/autobackupsh.log)
It didn't dump any output into it, strangely.

jschiwal 04-09-2011 06:16 AM

You don't want to print anything in a cron job, since there is no attached terminal. The use of -v is an error unless you redirect to a log file or /dev/null.

Redirect both stdout and stderr. e.g. >tar.log 2>&1


All times are GMT -5. The time now is 03:19 PM.