fi
#expand the exclude-path for use with tar
- exf=`ssh $computer "ls ~/.backup/exclude"`
+ exf=`ssh root@$computer "ls ~/.backup/exclude"`
#We try to run tar on the remote computer
# z gzip it
# ..to dd, to output to a file. We surpress messages from dd.
# And at last, redirect stderr to stdout, to get output logged.
TARFILE=$DATE.tmp
- TARCMD="ssh $computer \"$tar --one-file-system -zcf - -C $filesystem . $lastcmd \
+ TARCMD="ssh root@$computer \"$tar --one-file-system -zcf - -C $filesystem . $lastcmd \
--exclude-from=$exf\" > $TARFILE"
echo `date`" $computer: Running $TARCMD" >&2
-
- if eval $TARCMD; then
+ eval $TARCMD;
+ if [ -s $TARFILE ]; then
mv $TARFILE $DATE.tgz
#make a filelist.
#update the datefile if the filelist is ok.
echo `date`" $computer: Backing up $computer" >&2
# Try to SSH to the computer without entering a password.
- if ! `ssh -n -o NumberOfPasswordPrompts=0 $computer /bin/true`; then
+ if ! `ssh -n -o NumberOfPasswordPrompts=0 root@$computer /bin/true`; then
echo `date`" $computer: Could not use passwordless SSH."
# We don't want to return 0
R=1
- break;
+ # Do next computer
+ continue;
fi
#tømmer variabelen for sikkerhets skyld
filesystems=""
#Sjekker nest siste felt i fstab. Om det er 0 tar vi ikke backup
- filesystems=`ssh -n $computer "cat /etc/fstab" \
+ filesystems=`ssh -n root@$computer "cat /etc/fstab" \
| grep -v nfs \
| grep -v "^#" \
| grep -v "^$" \
| awk '{ if ( $(NF-1) != "0" ) print $2}' `
#clean up our dir at this client
- if ! ssh $computer "rm -r ~/.backup ; mkdir -m 700 ~/.backup"; then
- echo `date`" $computer: Could not create backup staging area at $computer:~/.backup"
+ if ! ssh root@$computer "rm -r ~/.backup ; mkdir -m 700 ~/.backup"; then
+ echo `date`" $computer: Could not create backup staging area at $computer:~/.backup - skipping backup of $computer"
# We don't want to return 0
R=1
- break;
+ continue;
fi
#try to copy $exclude to $computer
- if ! scp $exclude $computer:~/.backup/exclude > /dev/null; then
- echo `date`" $computer: Could not copy exclude.txt to $computer"
+ if ! scp $exclude root@$computer:~/.backup/exclude > /dev/null; then
+ echo `date`" $computer: Could not copy exclude.txt to $computer - skipping backup of $computer"
# We don't want to return 0
R=1
- break;
+ continue;
fi
#try to copy preeexec and postexec if they exist
# TODO: Gah, clean this mess!
[ -f $confdir/preexec.$computer ] && (
- scp $confdir/preexec.$computer $computer:~/.backup/preexec ||
- ( echo `date`" $computer: Could not copy preexec.$computer to $computer:~/.backup/preexec";
+ scp $confdir/preexec.$computer root@$computer:~/.backup/preexec >&2 ||
+ ( echo `date`" $computer: Could not copy preexec.$computer to $computer:~/.backup/preexec - skipping backup of $computer"
R=1
- break
+ continue
)
)
[ -f $confdir/postexec.$computer ] && (
- scp $confdir/postexec.$computer $computer:~/.backup/postexec ||
- ( echo `date`" $computer: Could not copy postexec.$computer to $computer:~/.backup/postexec"
- break
+ scp $confdir/postexec.$computer root@$computer:~/.backup/postexec >&2 ||
+ ( echo `date`" $computer: Could not copy postexec.$computer to $computer:~/.backup/postexec - skipping backup of $computer"
R=1
+ continue
)
)
#try to run preexec if it exist
- ssh $computer "[ -f ~/.backup/preexec ] && /bin/bash -x ~/.backup/preexec"
+ if ! ssh root@$computer "[ ! -f ~/.backup/preexec ] || /bin/bash -x ~/.backup/preexec" >&2; then
+ echo `date`" $computer: Could not run $computer:~/.backup/preexec - skipping backup of $computer"
+ R=1
+ continue
+ fi
+
for filesystem in $filesystems
do
done
#try to run postexec if it exist
- ssh $computer "[ -f ~/.backup/postexec ] && /bin/bash -x ~/.backup/postexec"
+ if ! ssh root@$computer "[ ! -f ~/.backup/postexec ] || /bin/bash -x ~/.backup/postexec" >&2; then
+ echo `date`" $computer: Could not run $computer:~/.backup/postexec"
+ R=1
+ fi
)
done &
rm $LOCKFILE
# Did anything go wrong?
+# (IMPORTANT NOTE: The R-business does not work as expected, since this script
+# forks itself.
if [ $R != 0 ]; then
echo `date`": Backup run ended with errors, check logs."
exit 1