help-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-tar] tar: Child returned status 1, Error is not recoverable: exiti


From: Robert Kudyba
Subject: [Help-tar] tar: Child returned status 1, Error is not recoverable: exiting now
Date: Tue, 7 Feb 2017 10:05:45 -0500

We are on Fedora 25 using the Drobo FS NAS and we run a nightly tar backup. Note it does include the aquota.user file but below you can see abide by this comment:
# Because aquota.user cannot have its atime reset, tar will give
# an error status=2 if --atime-preserve is used when backing it up.
# We don't want to lose the backup of this file but we also don't
# want to routinely ignore tar status=2.  Solution is to make
# --atime-preserve a per-backup argument and omit it when backing
# up aquota.user separately.
Here are the errors:
/bin/tar: home/users/aquota.user: Cannot utime: Operation not permitted
/bin/tar: Exiting with failure status due to previous errors

Backup of /home/users FAILED

Failed to rename /ourserver/ourdroboserver/ourdomain/home-users-new.tgz to
/ourserver/ourdroboserver/ourdomain/home-users-FAILED.tgz: File exists
Backed up /home/users/aquota.user to
/ourserver/ourdroboserver/ourdomain/home-users-aquota.user.tgz

gzip: stdout: Input/output error
/bin/tar: Child returned status 1
/bin/tar: Error is not recoverable: exiting now

Backup of /home FAILED

Backed up /home to /ourserver/ourdroboserver/ourdomain/home-FAILED.tgz
Backed up /etc to /ourserver/ourdroboserver/ourdomain/etc.tgz
Backed up /root to /ourserver/ourdroboserver/ourdomain/root.tgz
Backed up /usr/local to /ourserver/ourdroboserver/ourdomain/usr-local.tgz
Backed up /var/lib to /ourserver/ourdroboserver/ourdomain/var-lib.tgz
Backed up /var/backup to /ourserver/ourdroboserver/ourdomain/var-backup.tgz
Backed up /var/log to /ourserver/ourdroboserver/ourdomain/var-log.tgz
Backed up /var/spool to /ourserver/ourdroboserver/ourdomain/var-spool.tgz
Backed up /var/www to /ourserver/ourdroboserver/ourdomain/var-www.tgz
Backed up /var/yp to /ourserver/ourdroboserver/ourdomain/var-yp.tgz

Here are the options in the config file:

tarargs= --one-file-system --warning=no-file-ignored --warning=no-file-changed --warning=no-file-removed
backup = /home/users --atime-preserve --exclude=aquota.user --exclude=.gvfs --exclude=--exclude-ignore-recursive=S.gpg-agent --exclude=.adobe --exclude=.config/libvirt/qemu/lib/capabilities.monitor.sock --exclude=.dropbox --exclude=home/users/*/.cache --exclude=.fontconfig --exclude=csga/*/S.gpg-agent --exclude-caches-all
backup = /home/users/aquota.user
backup = /home --atime-preserve --exclude=.gvfs --exclude=.gnupg
backup = /etc --atime-preserve
backup = /root --atime-preserve --exclude=.cache --exclude=.cache/keyring-* --exclude-caches-all
backup = /usr/local --atime-preserve
backup    = /var/lib --atime-preserve --exclude=var/lib/rpm --exclude=var/lib/yum --exclude=mysql/mysql.sock --exclude=gssproxy/default.sock --exclude=samba/private/msg.sock
backup    = /var/backup --atime-preserve
backup    = /var/log --atime-preserve
backup    = /var/spool --atime-preserve
backup    = /var/www --atime-preserve

Here is the full backup script:

use POSIX;
# Global variables
# Host name will be used as name of directory for backups on drobo
my($hostname)=`/bin/hostname`;
chomp($hostname);
my($configfile)="/etc/drobo-backup.conf";
my($tar)="/bin/tar";        # Path to tar utility
my($mkdir)="/bin/mkdir";    # Path to mkdir utility
my($verbose)=0;
my($testmode)=0;

sub Usage {
    print "Usage: drobo-backup [-v] [-c configfile]\n";
    print "   -v : verbose mode";
    print "   -c : specify configuration file (default $configfile)";
    print "   -n : printd but don't execute commands (for testing config)";
    exit 1;
}

# Subroutine to back up one directory to drobo
sub do_backup {
    my($drobo,$args,$backup,$cond) = @_;

# The backup arg may include per-backup tar args.  Strip off these
# and quotes to get at the filename
    my($backuppath)=$backup;
# If quoted, remove quotes for naming.  Otherwise it is required not
# not to have embedded blanks so that per-backup tar arguments may follow.
    if( $backuppath =~ /^"([^"]*)"/ ) { # double quotes
    $backuppath = $1;
    }
    elsif( $backuppath =~ /^'([^']*)'/ ) { # single quotes
    $backuppath = $1;
    }
    elsif( $backuppath =~ /^(\S*)/ ) { # otherwise no blanks in path
    $backuppath = $1;
    }

    if( -d $backuppath || -f $backuppath ) { # check it is a valid dir or file
    my($drobodir) = "$drobo/$hostname";
    # make sure the drobo subdirectory for this host exists
    my($mkdircmd) = "$mkdir $drobodir";
    if( $verbose ) {
        print "$mkdircmd\n";
    }
    if( ! ($testmode || -d $drobodir) ) {
        system($mkdircmd);
    }
    # if it did not work, bail.
    if( ! ($testmode || -d $drobodir) ) {
        print "Failed to create destination dir $drobodir\n";
        exit 1;
    }
# construct tarfile name, e.g. usr-local.tgz
    my($backupfilestem) = $backuppath;
                # Sanitize the tarfile name
    while($backupfilestem =~ s,^/,,) { next; } # remove any leading slash(es)
    while($backupfilestem =~ s,/$,,) { next; } # remove any trailing slash(es)
    $backupfilestem =~ s,/,-,g; # all internal slashes become hyphens
    $backupfilestem =~ s/[^-\.\w]/X/g;# all remaining non-word chars exc . become X

    my($backupname)="$drobodir/$backupfilestem-new.tgz";
    my($backuprename) = "$drobodir/$backupfilestem.tgz";
#   $backup =~ s|/|| if $backup =~ m|^['"]?/|; # remove any leading slash
#   my($tarcmd) = "$tar -C / -czf $backupname $args $backup";

    my($tarcmd);
    if($backup =~ m|^['"]?/|){
       $backup =~ s|/||;  # remove any leading slash
       $tarcmd = "ionice -c2 -n7 nice -n19 $tar -czf $backupname -C / $args $backup";
    }else{
       $tarcmd = "ionice -c2 -n7 nice -n19 $tar -czf $backupname $args $backup";
    }

    if( $cond ) {
        $cond =~ s/^\[//;   # remove the [ ] around condition
        $cond =~ s/\]$//;
        $cond =~ s/BKPATH/$backuppath/g; # convenience substitutions
        $cond =~ s/TARFILE/$backuprename/g;
        $cond =~ s/TARDIR/$drobodir/g;
    }
    if( $cond && WEXITSTATUS(system("test $cond")) != 0 ) {
        if( $verbose ) {
        print "Condition [$cond] tests false\n";
        print "No backup of $backuppath\n";
        }
    }
    else {
        if( $verbose ) {
        if( $cond ) {
            print "Condition [$cond] tests true\n";
        }
        print "$tarcmd\n";
        }
    # tar returns 0 for success, 1 for warnings such as file changed while
    # being copied.  So we take either as meaning success.  Rename foo-new.tgz
    # to the (usually existing) foo.tgz.  N.B. system() returns status<<8.
        if( !$testmode ) {
        if( WEXITSTATUS(system($tarcmd)) >= 2 ) {
            print "\nBackup of $backuppath FAILED\n\n";
            # to avoid bad backup being renamed to good in second try, call it bad
            $backuprename = "$drobodir/$backupfilestem-FAILED.tgz";
        }
        if( rename("$backupname","$backuprename") ) {
            print "Backed up $backuppath to $backuprename\n";
        }
        else {
            print "Failed to rename $backupname to $backuprename: $!\n";
        }
        }
    }
    }
    else {
    print "$backuppath is not a directory or file\n";
    }
}



# default arguments to use on every backup
my($tarargs)="--atime-preserve --one-file-system --warning=no-file-ignored --warning=no-file-changed --warning=no-file-removed";


# set default drobopath according network

my($drobopath)="/domain/subdomain"; # cis value
if($hostname =~ /\.our\.domain\.edu/) {
    $drobopath="/domain/subdomain"; # dsm value
}


# Process command line arguments
while(@ARGV) {
    if( $ARGV[0] eq "-c" ) {    # -c configfile
    shift (@ARGV);
    if(@ARGV) {
        $configfile = $ARGV[0];
    }
    else {
        Usage();
    }
    }
    elsif( $ARGV[0] eq "-v" ) { # -v (verbose mode)
    ++$verbose;
    }
    elsif( $ARGV[0] eq "-n" ) { # -n (no-exec mode)
    $testmode = 1;
    }
    else {          # unrecognized argument
    Usage();
    }

    shift (@ARGV);
}


open(CONFIGFILE,$configfile) || die("Cannot open configfile $configfile: $!");

if($verbose) {
    print "Reading configfile $configfile\n";
}

my(@backup);
my(%condition);
my($configline) = 0;
foreach (<CONFIGFILE>) {
    $configline++;
    if( /^\s*#/ || /^\s*$/ ) {  # skip blank & comment lines (first nonblank is #)
    next;
    }
                # drobo=/path/to/drobo
    if( /^\s*drobo\s*=\s*(.*)$/ ) {
    $drobopath=$1;
    }
                # tarargs=global tar arguments
    elsif( /^\s*tarargs\s*=\s*(.*)$/ ) {
    $tarargs=$1;
    }
                # backup [condition] =/path/for/backup [tar args]
    elsif( /^\s*backup\s*(\[[^\]]*\])?\s*=\s*(.*)$/ ) {
    push(@backup,$2);
    if( $1 ) {
        $condition{$2} = $1;
    }
    }
    else {
    print "Unknown config directive at line $configline in $configfile:\n";
    print;
    exit 1;
    }
}

close(CONFIGFILE);


my($path);
foreach $path (@backup) {
    do_backup($drobopath,$tarargs,$path,$condition{$path});
}


# For unknown reason, rename of some files often fails.  Try again here.

foreach $tarfile ( glob("$drobopath/$hostname/*-new.tgz") ) {
    $rename_name = $tarfile;
    $rename_name =~ s/-new\.tgz$/.tgz/;
    if( rename($tarfile,$rename_name) ) {
    print "Second try renamed $tarfile to $rename_name\n";
    }
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]