-#!/bin/sh
+#!/bin/bash
# backup.sh
#
# Backup up Unix-like computers
# mind when hacking:
#
# KISS. And by that I mean really simple. Only regular Unix commands, please
-# (but GNU extensions are used).
+# (but GNU extensions are used and moreutils has to be installed).
#
# Because of the way we run this script from cron, informational logging goes
# to stderr and warnings and errors to stdout. This way, we get mail whenever
# stuff fails, and other output is redirected to the log file.
#
-# The computers are backed up in parallell (but the filesystems on each
+# The computers are backed up in parallel (but the filesystems on each
# computer in serial). This is implemented highly simplistic, with forking
# subshells. The script has no concept about threads, and stuff might go wrong,
# which usually requires manual cleanups.
# Backup only one computer, from command line?
if [ $1 ] ; then
unixcomputers=$1
-fi;
-
+fi
#selve backupen
# krever at noen variabler er satt
lastcmd=""
fi
- #if this client has a special tar
- #we need to find a better solution to this conf-issue
- if [ -f $confdir/tar.$computer ] ; then
- tar=`cat $confdir/tar.$computer`
- else
- tar=tar
- fi
-
# expand the exclude-path for use with tar
exf=`ssh root@$computer "ls ~/.backup/exclude"`
# 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 \"$tar --one-file-system -zcf - -C $filesystem . $lastcmd \
+ TARCMD="ssh root@$computer \"nice -n 19 ionice -c3 tar --one-file-system -zcf - -C $filesystem . $lastcmd \
--exclude-from=$exf\" | pee \"cat > $TARFILE\" \"tar tzvf -\""
echo `date`" $computer: Running $TARCMD" >&2
eval $TARCMD > $DATE.idx
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
sfilesystem=`echo $filesystem | tr '\/\$' '__'`
# Prepare storage area
- mkdir -m 755 -p $storagedir/$computer/$sfilesystem/{full,daglig} 2>/dev/null
+ mkdir -m 755 -p $storagedir/$computer/$sfilesystem/full 2>/dev/null
+ mkdir -m 755 -p $storagedir/$computer/$sfilesystem/daglig 2>/dev/null
echo $filesystem > ${storagedir}/${computer}/.${sfilesystem}.name
chmod 644 ${storagedir}/${computer}/.${sfilesystem}.name
echo $DATEs > $storagedir/$computer/$sfilesystem/.date
fi
- # Check if we want a full backup
- printf " $computer $filesystem: $confdir/fastfullbackupdag.$computer.$sfilesystem\n"
+ # Check if we want a full backup - Debug statement that causes noise in cron mail:
+ # printf " $computer $filesystem: $confdir/fastfullbackupdag.$computer.$sfilesystem\n"
if [ -f $confdir/fastfullbackupdag.$computer.$sfilesystem ]; then
fullbackup_min_for_this_machine=$dagermellomfulleforfast
if [ "$DAY_OF_MONTH" = "`cat $confdir/fastfullbackupdag.$computer.$sfilesystem`" ]; then