Changeset 2248

Show
Ignore:
Timestamp:
21/08/2008 11:54:01 (5 months ago)
Author:
chris
Message:

Handle sysadmin notifications and calculate next sync time in
BackupDaemon::RunSyncNow?, moved from RunSyncNowWithExceptionHandling?,
which just does the exception handling. We want to replace the exception
handling in Boxi, but not the other stuff.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupd/BackupDaemon.cpp

    r2245 r2248  
    276276        { 
    277277                BOX_WARNING( 
    278                                 "==============================================================================\n" 
    279                                 "SECURITY WARNING: This platform cannot check the credentials of connections to\n" 
    280                                 "the command socket. This is a potential DoS security problem.\n" 
    281                                 "Remove the CommandSocket directive from the bbackupd.conf file if bbackupctl\n" 
    282                                 "is not used.\n" 
    283                                 "==============================================================================\n" 
     278                        "==============================================================================\n" 
     279                        "SECURITY WARNING: This platform cannot check the credentials of connections to\n" 
     280                        "the command socket. This is a potential DoS security problem.\n" 
     281                        "Remove the CommandSocket directive from the bbackupd.conf file if bbackupctl\n" 
     282                        "is not used.\n" 
     283                        "==============================================================================\n" 
    284284                        ); 
    285285        } 
     
    867867void BackupDaemon::RunSyncNowWithExceptionHandling() 
    868868{ 
    869         // Touch a file to record times in filesystem 
    870         TouchFileInWorkingDir("last_sync_start"); 
    871  
    872         // Tell anything connected to the command socket 
    873         SendSyncStartOrFinish(true /* start */); 
    874          
    875         // Reset statistics on uploads 
    876         BackupStoreFile::ResetStats(); 
    877          
    878         // Delete the serialised store object file, 
    879         // so that we don't try to reload it after a 
    880         // partially completed backup 
    881         if(mDeleteStoreObjectInfoFile &&  
    882                 !DeleteStoreObjectInfo()) 
    883         { 
    884                 BOX_ERROR("Failed to delete the " 
    885                         "StoreObjectInfoFile, backup cannot " 
    886                         "continue safely."); 
    887                 THROW_EXCEPTION(ClientException,  
    888                         FailedToDeleteStoreObjectInfoFile); 
    889         } 
    890  
    891         // In case the backup throws an exception, 
    892         // we should not try to delete the store info 
    893         // object file again. 
    894         mDeleteStoreObjectInfoFile = false; 
    895          
    896869        // Do sync 
    897870        bool errorOccurred = false; 
     
    901874        try 
    902875        { 
    903                 // Notify administrator 
    904                 NotifySysadmin(NotifyEvent_BackupStart); 
    905  
    906876                RunSyncNow(); 
    907  
    908                 // Errors reading any files? 
    909                 if(mReadErrorsOnFilesystemObjects) 
    910                 { 
    911                         // Notify administrator 
    912                         NotifySysadmin(NotifyEvent_ReadError); 
    913                 } 
    914                 else 
    915                 { 
    916                         // Unset the read error flag, so the 
    917                         // error is reported again if it 
    918                         // happens again 
    919                         mNotificationsSent[NotifyEvent_ReadError] = false; 
    920                 } 
    921                  
    922                 // Check the storage limit 
    923                 if(mStorageLimitExceeded) 
    924                 { 
    925                         // Tell the sysadmin about this 
    926                         NotifySysadmin(NotifyEvent_StoreFull); 
    927                 } 
    928                 else 
    929                 { 
    930                         // unflag the storage full notify flag 
    931                         // so that next time the store is full, 
    932                         // an alert will be sent 
    933                         mNotificationsSent[NotifyEvent_StoreFull] = false; 
    934                 } 
    935                  
    936                 // Calculate when the next sync run should be 
    937                 mNextSyncTime = mCurrentSyncStartTime +  
    938                         mUpdateStoreInterval +  
    939                         Random::RandomInt(mUpdateStoreInterval >> 
    940                         SYNC_PERIOD_RANDOM_EXTRA_TIME_SHIFT_BY); 
    941          
    942                 // Notify administrator 
    943                 NotifySysadmin(NotifyEvent_BackupFinish); 
    944  
    945                 // -------------------------------------------------------------------------------------------- 
    946  
    947                 // We had a successful backup, save the store  
    948                 // info. If we save successfully, we must  
    949                 // delete the file next time we start a backup 
    950  
    951                 mDeleteStoreObjectInfoFile =  
    952                         SerializeStoreObjectInfo(mLastSyncTime, 
    953                                 mNextSyncTime); 
    954  
    955                 // -------------------------------------------------------------------------------------------- 
    956  
    957                 // If we were retrying after an error, 
    958                 // now would be a good time to stop :-) 
    959                 mDoSyncForcedByPreviousSyncError = false; 
    960877        } 
    961878        catch(BoxException &e) 
     
    1035952                        mNextSyncTime = mCurrentSyncStartTime +  
    1036953                                SecondsToBoxTime(100) + 
    1037                                 Random::RandomInt( 
    1038                                         mUpdateStoreInterval >>  
     954                                Random::RandomInt(mUpdateStoreInterval >>  
    1039955                                        SYNC_PERIOD_RANDOM_EXTRA_TIME_SHIFT_BY); 
    1040                         mDoSyncForcedByPreviousSyncError = true; 
    1041956                } 
    1042957        } 
     
    1048963                mNotificationsSent[NotifyEvent_BackupError] = false; 
    1049964        } 
     965 
     966        // If we were retrying after an error, 
     967        // now would be a good time to stop :-) 
     968        mDoSyncForcedByPreviousSyncError = errorOccurred; 
    1050969 
    1051970        // Log the stats 
     
    1067986void BackupDaemon::RunSyncNow() 
    1068987{ 
     988        // Touch a file to record times in filesystem 
     989        TouchFileInWorkingDir("last_sync_start"); 
     990 
     991        // Tell anything connected to the command socket 
     992        SendSyncStartOrFinish(true /* start */); 
     993         
     994        // Reset statistics on uploads 
     995        BackupStoreFile::ResetStats(); 
     996         
     997        // Delete the serialised store object file, 
     998        // so that we don't try to reload it after a 
     999        // partially completed backup 
     1000        if(mDeleteStoreObjectInfoFile &&  
     1001                !DeleteStoreObjectInfo()) 
     1002        { 
     1003                BOX_ERROR("Failed to delete the " 
     1004                        "StoreObjectInfoFile, backup cannot " 
     1005                        "continue safely."); 
     1006                THROW_EXCEPTION(ClientException,  
     1007                        FailedToDeleteStoreObjectInfoFile); 
     1008        } 
     1009 
     1010        // In case the backup throws an exception, 
     1011        // we should not try to delete the store info 
     1012        // object file again. 
     1013        mDeleteStoreObjectInfoFile = false; 
     1014 
     1015        // Notify administrator 
     1016        NotifySysadmin(NotifyEvent_BackupStart); 
     1017 
    10691018        // Set state and log start 
    10701019        SetState(State_Connected); 
     
    12991248        // Log 
    13001249        BOX_NOTICE("Finished scan of local files"); 
     1250 
     1251         
     1252        // Errors reading any files? 
     1253        if(mReadErrorsOnFilesystemObjects) 
     1254        { 
     1255                // Notify administrator 
     1256                NotifySysadmin(NotifyEvent_ReadError); 
     1257        } 
     1258        else 
     1259        { 
     1260                // Unset the read error flag, so the 
     1261                // error is reported again if it 
     1262                // happens again 
     1263                mNotificationsSent[NotifyEvent_ReadError] = false; 
     1264        } 
     1265         
     1266        // Check the storage limit 
     1267        if(mStorageLimitExceeded) 
     1268        { 
     1269                // Tell the sysadmin about this 
     1270                NotifySysadmin(NotifyEvent_StoreFull); 
     1271        } 
     1272        else 
     1273        { 
     1274                // unflag the storage full notify flag 
     1275                // so that next time the store is full, 
     1276                // an alert will be sent 
     1277                mNotificationsSent[NotifyEvent_StoreFull] = false; 
     1278        } 
     1279         
     1280        // Calculate when the next sync run should be 
     1281        mNextSyncTime = mCurrentSyncStartTime +  
     1282                mUpdateStoreInterval +  
     1283                Random::RandomInt(mUpdateStoreInterval >> 
     1284                SYNC_PERIOD_RANDOM_EXTRA_TIME_SHIFT_BY); 
     1285 
     1286        // Notify administrator 
     1287        NotifySysadmin(NotifyEvent_BackupFinish); 
     1288 
     1289        // -------------------------------------------------------------------------------------------- 
     1290 
     1291        // We had a successful backup, save the store  
     1292        // info. If we save successfully, we must  
     1293        // delete the file next time we start a backup 
     1294 
     1295        mDeleteStoreObjectInfoFile =  
     1296                SerializeStoreObjectInfo(mLastSyncTime, 
     1297                        mNextSyncTime); 
     1298 
     1299        // -------------------------------------------------------------------------------------------- 
    13011300} 
    13021301 
     
    18501849        // Then... go through each of the entries in the configuration, 
    18511850        // making sure there's a directory created for it. 
    1852         for(std::list<std::pair<std::string, Configuration> >::const_iterator i = rLocationsConf.mSubConfigurations.begin(); 
    1853                 i != rLocationsConf.mSubConfigurations.end(); ++i) 
    1854         { 
    1855                 BOX_TRACE("new location: " << i->first); 
     1851        std::vector<std::string> locNames = 
     1852                rLocationsConf.GetSubConfigurationNames(); 
     1853         
     1854        for(std::vector<std::string>::iterator 
     1855                pLocName  = locNames.begin(); 
     1856                pLocName != locNames.end(); 
     1857                pLocName++) 
     1858        { 
     1859                const Configuration& rConfig( 
     1860                        rLocationsConf.GetSubConfiguration(*pLocName)); 
     1861                BOX_TRACE("new location: " << *pLocName); 
     1862                 
    18561863                // Create a record for it 
    18571864                std::auto_ptr<Location> apLoc(new Location); 
     
    18601867                { 
    18611868                        // Setup names in the location record 
    1862                         apLoc->mName = i->first; 
    1863                         apLoc->mPath = i->second.GetKeyValue("Path"); 
     1869                        apLoc->mName = *pLocName; 
     1870                        apLoc->mPath = rConfig.GetKeyValue("Path"); 
    18641871                         
    18651872                        // Read the exclude lists from the Configuration 
    1866                         apLoc->mpExcludeFiles = BackupClientMakeExcludeList_Files(i->second); 
    1867                         apLoc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(i->second); 
     1873                        apLoc->mpExcludeFiles = BackupClientMakeExcludeList_Files(rConfig); 
     1874                        apLoc->mpExcludeDirs = BackupClientMakeExcludeList_Dirs(rConfig); 
    18681875 
    18691876                        // Does this exist on the server? 
     
    20122019                        // Create and store the directory object for the root of this location 
    20132020                        ASSERT(oid != 0); 
    2014                         BackupClientDirectoryRecord *precord = new BackupClientDirectoryRecord(oid, i->first); 
     2021                        BackupClientDirectoryRecord *precord = 
     2022                                new BackupClientDirectoryRecord(oid, *pLocName); 
    20152023                        apLoc->mpDirectoryRecord.reset(precord); 
    20162024                         
     
    20902098void BackupDaemon::SetupIDMapsForSync() 
    20912099{ 
    2092         // Need to do different things depending on whether it's an in memory implementation, 
    2093         // or whether it's all stored on disc. 
     2100        // Need to do different things depending on whether it's an 
     2101        // in memory implementation, or whether it's all stored on disc. 
    20942102         
    20952103#ifdef BACKIPCLIENTINODETOIDMAP_IN_MEMORY_IMPLEMENTATION 
     
    20992107        FillIDMapVector(mNewIDMaps, true /* new maps */); 
    21002108 
    2101         // Then make sure that the current maps have objects, even if they are empty 
    2102         // (for the very first run) 
     2109        // Then make sure that the current maps have objects, 
     2110        // even if they are empty (for the very first run) 
    21032111        if(mCurrentIDMaps.empty()) 
    21042112        {