]> git.sesse.net Git - backup.sh/blobdiff - backup.sh
Do not create .date before the backup is done.
[backup.sh] / backup.sh
index c3143d71cd78f19495478b372369201a6a929696..5e0cfb57f2da14b07593638a099a2a2a4c959db9 100755 (executable)
--- a/backup.sh
+++ b/backup.sh
@@ -114,14 +114,18 @@ backup()
 
        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
-                       diemsg "Could not copy .incremental.snar from $computer"
+               if [ "$incrementalsnar" ]; then
+                       if ! scp root@$computer:$incrementalsnar $SNARFILE.tmp; then
+                               diemsg "Could not copy .incremental.snar from $computer"
+                       fi
                fi
 
                # Move tar file in place
                mv $TARFILE $DATE.tgz
-               mv $SNARFILE.tmp $SNARFILE
+               if [ "$incrementalsnar" ]; then
+                       mv $SNARFILE.tmp $SNARFILE
+               fi
 
                # Update timestamp
                echo $DATEs > ../.date && touch -t $DATE ../.date
@@ -213,11 +217,10 @@ for filesystem in $filesystems; do
        # Default backuplevel
        backuplevel=daglig
 
-       if [ ! -f $storagedir/$computer/$sfilesystem/.date ]
+       if [ ! -s $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
@@ -240,13 +243,15 @@ for filesystem in $filesystems; do
        fi
 
        # We want to be here
-       cd $storagedir/$computer/$sfilesystem/$backuplevelmsg || die "$storagedir/$computer/$sfilesystem/$backuplevel does not exist"
+       cd $storagedir/$computer/$sfilesystem/$backuplevel || diemsg "$storagedir/$computer/$sfilesystem/$backuplevel does not exist"
 
        # Perform the actual backup
        backup
 
        # Check if this box has a custom number of full backups
-       if [ -f $confdir/maksfulle.$computer ] ; then
+       if [ -f $confdir/maksfulle.$computer.$sfilesystem ]; then
+               mf=$((`cat $confdir/maksfulle.$computer`+1))
+       elif [ -f $confdir/maksfulle.$computer ] ; then
                mf=$((`cat $confdir/maksfulle.$computer`+1))
        else
                mf=$(($maxnumfull+1))
@@ -273,6 +278,9 @@ done
 if ! ssh root@$computer "[ ! -f /root/.backup/postexec ] || /bin/bash -x /root/.backup/postexec" >&2; then
        diemsg "Could not run $computer:/root/.backup/postexec"
 fi
+       
+echo `date`": $computer: Backup completed successfully."
+echo `date`": $computer: Backup completed successfully." >&2
 
 # Remove lockfile
 rm $LOCKFILE