+ echo -n `date` >&2
+ printf " $computer: $computer:$filesystem $backuplevel backup\n" >&2
+
+ SNARFILE="${storagedir}/${computer}/${sfilesystem}/.incremental.snar"
+ incrementalsnar="/root/.backup/${sfilesystem}.snar"
+ if [ "$backuplevel" = "daglig" ]
+ then
+ # If incremental backup, we need to copy the incremental status to $computer.
+ # If it does not exist, whine a bit and then run date-based instead.
+ if [ -s "$SNARFILE" ]; then
+ if ! scp $SNARFILE root@$computer:$incrementalsnar; then
+ echo `date`" $computer: Could not copy .incremental.snar to $computer"
+ die
+ fi
+ lastcmd="--listed-incremental=$incrementalsnar --no-check-device"
+ else
+ echo `date`" $computer: Missing incremental.snar for $filesystem, doing date-based backup instead until next full backup" >&2
+ incrementalsnar=""
+ lastd=`cat ../.date`
+ lastcmd="--newer='$lastd'"
+ fi
+ else
+ lastcmd="--listed-incremental=$incrementalsnar"
+ fi
+
+ # expand the exclude-path for use with tar
+ exf=`ssh root@$computer "ls ~/.backup/exclude"`
+
+ # We try to run tar on the remote computer
+ # c create archive
+ # C change to directory first
+ # . where to start taring (see C)
+ # $lastcmd only files newer than this
+ # --one-file-system don't traverse file systems
+ # --use-compress-program compress it using gzip or pigz
+ # --exclude-from file to get exclusion pattern from
+ # Pipe the stuff over ssh to ourselves, run pee to cat the contents to a
+ # file and build a file list, respectivly.
+ TARFILE=$DATE.tmp
+ TARCMD="ssh root@$computer \"nice -n 19 ionice -c3 tar --one-file-system --use-compress-program $compressor -cf - -C $filesystem . $lastcmd \
+ --exclude-from=$exf\" | pee \"cat > $TARFILE\" \"tar tzvf -\""
+ echo `date`" $computer: Running $TARCMD" >&2
+ eval $TARCMD > $DATE.idx
+
+ if [ $? -eq 0 ] && [ -s $TARFILE ]; then
+ # File is >0 in size and neither cat or tar tzvf failed; we assume it worked.
+
+ if ! scp root@$computer:$incrementalsnar $SNARFILE.tmp; then
+ echo `date`" $computer: Could not copy .incremental.snar from $computer"
+ die
+ fi
+
+ # Move tar file in place
+ mv $TARFILE $DATE.tgz
+ mv $SNARFILE.tmp $SNARFILE
+
+ # Update timestamp
+ echo $DATEs > ../.date && touch -t $DATE ../.date
+
+ # Make a sorted file list as well
+ sort -k6 < $DATE.idx > $DATE.sdx
+
+ # Fix permissions
+ chmod 600 *tgz #only for us
+ chmod 644 *sdx *idx 2>/dev/null #everyone can read
+
+ # Let the remote computer know that we ran a successful backup (for nagios)
+ ssh root@$computer touch $filesystem/.lastbackup
+ else
+ # Something wrong happened.
+ rm $TARFILE
+ echo `date`" $computer: $TARFILE empty. $backuplevel backup of $computer:$filesystem failed and deleted"
+ die
+ fi
+}