-
- #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 ". /tmp/.backup/env ; cat /etc/fstab" \
- | grep -v nfs \
- | grep -v ^# \
- | awk '{ if ( $(NF-1) != "0" ) print $2}' `
-
- #clean up our dir at this client
- ssh $computer "rm -rf /tmp/.backup ; mkdir -m 700 /tmp/.backup"
-
- #try to copy $exclude to $computer
- scp $exclude $computer:/tmp/.backup/exclude ||
- echo "could not copy exclude.txt to $computer :("
-
- #create env if it does not exist
- if [ ! -f $confdir/env.$computer ]
- touch $confdir/env.$computer
-
- #copy env to client
- scp $confdir/env.$computer $computer:/tmp/.backup/env
-
- #try to copy preeexec and postexec if they exist
- [ -f $confdir/preexec.$computer ] &&
- scp $confdir/preexec.$computer $computer:/tmp/.backup/preexec
- [ -f $confdir/postexec.$computer ] &&
- scp $confdir/postexec.$computer $computer:/tmp/.backup/postexec
-
- #try to run preexec if it exist
- ssh $computer ". /tmp/.backup/env ; [ -f /tmp/.backup/preexec ] && /bin/bash -x /tmp/.backup/preexec"
-
- for filesystem in $filesystems
- do
- #lager en variant uten tegnet "/" eller $ (gjelder NT)
- sfilesystem=`echo $filesystem | tr '\/\$' '__'`
-
- #lager det som trengs av kataloger
- mkdir -m 755 -p $storagedir/$computer/$sfilesystem/{full,daglig} 2>/dev/null
-
- #
- echo $filesystem > ${storagedir}/${computer}/.${sfilesystem}.name
- chmod 644 ${storagedir}/${computer}/.${sfilesystem}.name
-
- #set default backuplevel
- backuplevel=daglig
-
- if [ ! -f $storagedir/$computer/$sfilesystem/.date ]
- then
- #take the first full backup of this filesystem on this computer
- backuplevel=full
- echo $DATEs > $storagedir/$computer/$sfilesystem/.date
- fi
-
- #sjekker om det er på tide med en full
- if
- [ -z `find $storagedir/$computer/$sfilesystem/full/ -name \*tgz -mtime -$dagermellomfulle` ]
- then
- backuplevel=full
- fi
-
- #gå ned i rett katalog
- cd $storagedir/$computer/$sfilesystem/$backuplevel
-
- #perform the actual backup
- backup
-
- #delete complete backups
- mf=$(($maksantallfulle+1))
- for full in `ls -1t $storagedir/$computer/$sfilesystem/full/*tgz | tail +$mf`
- do
- prefix=`echo $full|cut -d . -f 1`
- echo "$computer:$filesystem sletter full $prefix (for mange)"
- rm $prefix*
- done
-
- #delete incremental backups older than the oldest complete backup
- oldf=`ls -t1 $storagedir/$computer/$sfilesystem/full/*tgz | tail -1`
- find \
- $storagedir/$computer/$sfilesystem/daglig \
- -type f \
- \! -newer $oldf \
- -exec rm {} \;
- #denne funker bare med gnu find
- #-printf "$computer:$filesystem sletter daglig %f (for gammel)\n" \
-
- done
-
- #try to run postexec if it exist
- ssh $computer ". /tmp/.backup/env ; [ -f /tmp/.backup/postexec ] && /bin/bash -x /tmp/.backup/postexec"
-
+ # Remove / and $ (for Windows) for path names
+ sfilesystem=`echo $filesystem | tr '\/\$' '__'`
+
+ # Prepare storage area
+ mkdir -m 755 -p $storagedir/$computer/$sfilesystem/full 2>/dev/null
+ mkdir -m 755 -p $storagedir/$computer/$sfilesystem/daglig 2>/dev/null
+
+ # Default backuplevel
+ backuplevel=daglig
+
+ if [ ! -f $storagedir/$computer/$sfilesystem/.date ]
+ then
+ # Take the first full backup of this filesystem on this computer
+ backuplevel=full
+ echo $DATEs > $storagedir/$computer/$sfilesystem/.date
+ fi
+
+ # Check if we want a full backup
+ if [ -f $confdir/fastfullbackupdag.$computer.$sfilesystem ]; then
+ fullbackup_min_for_this_machine=$daysbetweenfullforfixed
+ if [ "$DAY_OF_MONTH" = "`cat $confdir/fastfullbackupdag.$computer.$sfilesystem`" ]; then
+ backuplevel=full
+ fi
+ elif [ -f $confdir/fastfullbackupdag.$computer ]; then
+ fullbackup_min_for_this_machine=$daysbetweenfullforfixed
+ if [ "$DAY_OF_MONTH" = "`cat $confdir/fastfullbackupdag.$computer`" ]; then
+ backuplevel=full
+ fi
+ else
+ fullbackup_min_for_this_machine=$daysbetweenfull
+ fi
+
+ if [ -z "`find $storagedir/$computer/$sfilesystem/full/ -name \*tgz -mtime -$fullbackup_min_for_this_machine`" ]; then
+ backuplevel=full
+ fi
+
+ # We want to be here
+ cd $storagedir/$computer/$sfilesystem/$backuplevel || die
+
+ # Perform the actual backup
+ backup
+
+ # Check if this box has a custom number of full backups
+ if [ -f $confdir/maksfulle.$computer ] ; then
+ mf=$((`cat $confdir/maksfulle.$computer`+1))
+ else
+ mf=$(($maxnumfull+1))
+ fi
+
+ # Delete old full backups
+ for full in `ls -1t $storagedir/$computer/$sfilesystem/full/*tgz | tail -n +$mf`
+ do
+ prefix=`echo $full | sed "s/\.[^.]*$//"`
+ echo `date`": $computer:$filesystem Deleting full backup $prefix" >&2
+ rm $prefix*
+ done
+
+ # Delete incremental backups older than the oldest full backup
+ oldf=`ls -t1 $storagedir/$computer/$sfilesystem/full/*tgz | tail -1`
+ find \
+ $storagedir/$computer/$sfilesystem/daglig \
+ -type f \
+ \! -newer $oldf \
+ -printf "`date`: $computer: Deleting old incremental backup: %p\n" \
+ -exec rm {} \; >&2