From: root Date: Fri, 27 Jul 2007 01:24:38 +0000 (+0000) Subject: Støtter nå å kjøre som ikke-root. X-Git-Url: https://git.sesse.net/?p=backup.sh;a=commitdiff_plain;h=35ee17f5f1344cab950789aca51415dc4b8093c3 Støtter nå å kjøre som ikke-root. --- diff --git a/backup.sh b/backup.sh index c433030..fce079c 100755 --- a/backup.sh +++ b/backup.sh @@ -95,7 +95,7 @@ backup() 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 @@ -109,7 +109,7 @@ backup() # ..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 @@ -146,7 +146,7 @@ do 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 @@ -158,14 +158,14 @@ do 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 + if ! ssh root@$computer "rm -r ~/.backup ; mkdir -m 700 ~/.backup"; then echo `date`" $computer: Could not create backup staging area at $computer:~/.backup" # We don't want to return 0 R=1 @@ -173,7 +173,7 @@ do fi #try to copy $exclude to $computer - if ! scp $exclude $computer:~/.backup/exclude > /dev/null; then + if ! scp $exclude root@$computer:~/.backup/exclude > /dev/null; then echo `date`" $computer: Could not copy exclude.txt to $computer" # We don't want to return 0 R=1 @@ -183,14 +183,14 @@ do #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 || + scp $confdir/preexec.$computer root@$computer:~/.backup/preexec || ( echo `date`" $computer: Could not copy preexec.$computer to $computer:~/.backup/preexec"; R=1 break ) ) [ -f $confdir/postexec.$computer ] && ( - scp $confdir/postexec.$computer $computer:~/.backup/postexec || + scp $confdir/postexec.$computer root@$computer:~/.backup/postexec || ( echo `date`" $computer: Could not copy postexec.$computer to $computer:~/.backup/postexec" break R=1 @@ -198,7 +198,7 @@ do ) #try to run preexec if it exist - ssh $computer "[ -f ~/.backup/preexec ] && /bin/bash -x ~/.backup/preexec" + ssh root@$computer "[ -f ~/.backup/preexec ] && /bin/bash -x ~/.backup/preexec" for filesystem in $filesystems do @@ -258,7 +258,7 @@ do done #try to run postexec if it exist - ssh $computer "[ -f ~/.backup/postexec ] && /bin/bash -x ~/.backup/postexec" + ssh root@$computer "[ -f ~/.backup/postexec ] && /bin/bash -x ~/.backup/postexec" ) done &