LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-06-2008, 01:11 PM   #1
StikShift
LQ Newbie
 
Registered: Jan 2004
Posts: 14

Rep: Reputation: 0
USB tar backups fail in cron, not from command line


Title: USB tar backups fail in cron, not from command line

I use the --listed-incremental feature in tar to perform backups on my system. I have a script that performs this operation, and the script is run by cron in the wee hours of the morning. It has worked great for years, but I've run into a recent problem when using removable USB memory sticks. The script runs perfectly in cron as long as I don't try to backup anything off the USB stick with it.

If the contents of the stick, or a subdirectory on it are set to be backed up in the list. The incremental backup works perfectly when run from the command line. Unfortunately, when it runs in cron, I get an empty tar archive. I don't understand this, and I've had no success at debugging it. I suspect a problem with environmental variables, but again, I've been unable to debug it. Here is a copy of my crontab:

45 03 * * * /usr/local/sbin/bak3/incr-bak.pl > /var/bak3/incr-bak.log

As you can see, I've used the full path to everything.

I've seen this problem on Mandriva as well as Kubuntu. It does not occur on Fedora 8 or Debian Etch. I suppose I could use those distros, but Mandriva is a fine distro, as is Kubuntu. There are many situations where these would be a better choice.

Thanks for any insight you might provide.

Galen Overstreet
 
Old 03-06-2008, 01:21 PM   #2
lord-fu
Member
 
Registered: Apr 2005
Location: Ohio
Distribution: Slackware && freeBSD
Posts: 676

Rep: Reputation: 30
What does your logs say during this time? Could you not put some debugging code within the backup script itself to help find out where something is going wrong? Is it a sudo problem? Maybe a mounting problem, permissions etc?


I know it is not an answer but at least maybe a direction.

hth
 
Old 03-06-2008, 04:36 PM   #3
StikShift
LQ Newbie
 
Registered: Jan 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Nothing is amiss according to the logs. It all seems to work perfectly, except that the tar file is empty. This only happens when I try to back up files from the USB stick.

My "old" workstation ran Fedora 8, and Debian Etch before that. Both were set up the same as the Mandriva 2008, but neither had this problem.

Again, I'm at a loss to debug it, since it seems to work fine. I've tried all kinds of things with environmental variables, etc, but the problem persists. I'll keep tinkering.....

Thanks for your input!!!

Galen
 
Old 03-06-2008, 08:01 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
Can you post the script? Does it use system calls that don't have the full path to the command and not check the result? I'm just guessing without seeing how the script sets up its environment and operates.
 
Old 03-06-2008, 11:40 PM   #5
StikShift
LQ Newbie
 
Registered: Jan 2004
Posts: 14

Original Poster
Rep: Reputation: 0
It's in perl, but...here you go. This is the "incremental" script, which is the one I run in cron. I usually run the full backups manually. For more info (including the "full" backup script & docs) at:


http://www.ostreet.net/software/bak3.html


Thanks for your help!

Galen

+++++++++++++++++++++++++++++++++++++++++++++
!/usr/bin/perl -w
#
# Copyright 2004 G. P. Overstreet
#
#
#
# This file is part of bak3 - Unix/Linux Backup Scripts.
#
# bak3 - Unix/Linux Backup Scripts is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# bak3 - Unix/Linux Backup Scripts is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with bak3 - Unix/Linux Backup Scripts; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#
#
# Version 3 Backup Script
# Incremental Backup
# GPO 5/11/04
#
# Last Mod GPO
# 6/28/04
#
# Set paths to conf files in /etc
$etc_path = "/etc/bak3";
$conf_file = "$etc_path/bak3.conf";
open (CONF, "<$conf_file")
|| die "Can't Open file $!";
#
# Read conf file, set local variable names/values
while (<CONF>) {
@var = split;
if ($var[0] eq "local_work") {$local_work = $var[2];}
if ($var[0] eq "fname") {$fname = $var[2];}
if ($var[0] eq "numincr") {$numincr = $var[2];}
if ($var[0] eq "encrypt_opt") {$encrypt_opt = $var[2];}
if ($var[0] eq "encrypt_key_id") {$encrypt_key_id = $var[2];}
if ($var[0] eq "incr_stor_opt") {$incr_stor_opt = $var[2];}
if ($var[0] eq "remote_user") {$remote_user = $var[2];}
if ($var[0] eq "remote_host") {$remote_host = $var[2];}
if ($var[0] eq "remote_full_path") {$remote_full_path = $var[2];}
if ($var[0] eq "numskipday") {$numskipday = $var[2];}
if ($var[0] eq "util_opt") {$util_opt = $var[2];}
if ($var[0] eq "scriptpath") {$scriptpath = $var[2];}
}
close CONF;
#
# Open last for input; Read in increment number of last incr backup
$verfile = "$local_work/last-incr";
open (INFILE, "<$verfile")
|| die "Can't Open file $!";
while (<INFILE>) {
# $iver = $_;
# $skiplast = $_;
@var = split;
}
close INFILE;
#
$iver = $var[0];
$skiplast = $var[1];
#$voo = chomp $iver;
#$voo2 = chomp $skiplast;
#
# Check if you want to write remote incremental this time
$skiplast = $skiplast + 1;
if ($skiplast eq $numskipday) {
$skiplast = 0;
}
# Create filename for new full backup; increment & write new number
$old_tar_name = "$fname-full-$iver.tar";
print $old_tar_name, "\n";
for ($count = 1; $count <= $numincr; $count++) {
if ($iver eq $count) {
$foo = $iver + 1;
}
if ($iver eq $numincr) {
$foo = 1;
}
}
$new_tar_name = "$fname-incr-$foo";
open (OUTFILE, ">$verfile")
|| die "Can't Open file $!";
print OUTFILE "$foo $skiplast";
close OUTFILE;
#
# Tar the new backup file
system $vook = "cp $local_work/incr-full.dat $local_work/incr.dat";
system $vook = "tar -cvpf $new_tar_name.tar --listed-incremental $loc#
# gzip or encrypt the new backup tar file
if ($encrypt_opt eq 0) {
system $vook = "gzip -f $new_tar_name.tar";
$copy_name = "$new_tar_name.tar.gz";
}
if ($encrypt_opt eq 1) {
system $vook = "gpg -r $encrypt_key_id -e $new_tar_name.tar";
$copy_name = "$new_tar_name.tar.gpg";
system $vook = "rm $new_tar_name.tar";
}
#
# Skip remote for skipdays
if ($skiplast ne 0) {
goto NOREMOTE;
$skiplast = $skiplast + 1;
}
# copy to remote server
#
if ($incr_stor_opt gt 0) {
$vook2 = "$local_work/sftp-batch";
open (OUTFILE, ">$vook2")
|| die "Can't Open file $!";
print OUTFILE "put $copy_name $remote_full_path\nquit";
close OUTFILE;
system $vook = "sftp -b $vook2 $remote_user$remote_host";
}
NOREMOTE:
# delete local copy for incr_stor_opt = 2
if ($incr_stor_opt eq 2) {
system $vook = "rm $copy_name";
}
# Delete previous incremental backup locally if incr_stor_opt = 3
if ($incr_stor_opt eq 3) {
system $vook = "rm $fname-incr-$iver*";
}
# Run optional utility script after incremental backup is complete
if ($util_opt eq 1) {
system $vook = "$scriptpath";
}
#
al_work/incr.dat -T $etc_path/backup.files.list";
 
Old 03-10-2008, 05:54 PM   #6
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
The only suggestion I have is to change the commands in the system calls (gpg, etc.) to use the full path to the command. It may be failing because it's not finding the commands.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Works from command line but not from the cron WingnutOne Linux - General 8 11-08-2007 08:18 AM
Backups (tar and gzip) fail due to auditd -- please help jdh239 Linux - Server 1 11-07-2007 12:08 PM
LXer: Taking backups using tar command in Linux and unix LXer Syndicated Linux News 0 04-18-2006 10:03 AM
security for backups (tar command) wedgeworth Linux - Software 1 03-18-2004 11:00 AM
cron jobs - tar scp in one line? bkeating Linux - Software 1 11-04-2003 03:49 PM


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

Main Menu
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