LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 04-09-2011, 02:39 AM   #1
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Rep: Reputation: 1
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?

Last edited by wafflesausage; 04-09-2011 at 04:09 AM.
 
Old 04-09-2011, 05:34 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 345Reputation: 345Reputation: 345Reputation: 345
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...
 
Old 04-09-2011, 05:50 AM   #3
wafflesausage
Member
 
Registered: Oct 2010
Distribution: FreeBSD(preferred), Fedora 15, WebOS, Mac OS, NetBSD, Ubuntu (if I have no other choice)
Posts: 46

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Snark1994 View Post
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.
 
Old 04-09-2011, 07:16 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Unable to properly configure PowerDNS - Won't resolve domain name SpudLabs Linux - Software 7 04-01-2011 04:33 PM
Troubles using cron+tar for automated backup magli Linux - Software 18 07-14-2009 06:40 PM
Script not running properly in cron though runs well if run manually. linuxlover.chaitanya Linux - Newbie 4 01-15-2009 04:31 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 03:53 AM
using tar to extract properly xushi Slackware 9 03-05-2005 10:10 AM


All times are GMT -5. The time now is 06:37 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration