Changeset 2138


Ignore:
Timestamp:
09/04/2008 09:00:53 (4 years ago)
Author:
cbkm
Message:

Fix issue reported by MB of showing the same files in the report that were already backed up due to a non-rotated logfile. Added debug output (minimal at present). Added --sort and --debug to --help output.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/contrib/bbreporter/bbreporter.py

    r2137 r2138  
    8383                 log_file="/var/log/syslog", email_to=None,  
    8484                 email_from="report@boxbackup", rotate=False,  
    85                  verbose=False, stats=False, sort=False): 
     85                 verbose=False, stats=False, sort=False, debug=False): 
    8686         
    8787        # Config options 
     
    9494        self.usage_stats = stats 
    9595        self.sort_files = sort 
    96          
     96        self.debug = debug 
     97 
    9798        # Regex's 
    9899        self.re_automatic_backup = re.compile(" *AutomaticBackup *= *no", re.I) 
     
    103104        self.reset() 
    104105         
    105          
     106    def _debug(self, msg): 
     107        if self.debug: 
     108            sys.stderr.write("[bbreporter.py Debug]: %s\n" % msg) 
     109 
    106110    def reset(self): 
    107111        # Reset report data to default values 
     
    120124        try: 
    121125            self._determine_operating_mode() 
     126             
     127            if self.lazy_mode: 
     128                self._debug("Operating in LAZY MODE.") 
     129            else: 
     130                self._debug("Operating in SNAPSHOT MODE.") 
     131 
    122132        except IOError: 
    123133            raise BoxBackupReporter.BoxBackupReporterError("Error: "+\ 
     
    227237                    # so we only capture the most recent session. 
    228238                    if not self.lazy_mode or self.start_datetime == "Unknown": 
     239                        self._debug("Reset start dtime with old time: %s." %  
     240                                    self.start_datetime) 
     241                         
     242                        # Reset ourselves 
    229243                        self.reset() 
     244                         
     245                        # Reset our temporary variables which we store 
     246                        # the files in. 
     247                        patched_files = {} 
     248                        uploaded_files = {} 
     249                        synced_files = {} 
     250 
    230251                        self.start_datetime = data[1]+" "+data[0]+ " "+data[2] 
     252                        self._debug("Reset start dtime with new time %s." % 
     253                                    self.start_datetime) 
    231254                                               
    232255                # If we find the backup-finish event then set the end_datetime. 
    233256                elif data[6].find("backup-finish") > -1: 
    234257                    self.end_datetime = data[1] + " " + data[0] + " " + data[2] 
     258                    self._debug("Set end dtime: %s" % self.end_datetime) 
    235259                 
    236260                # Only log the events if we have our start time. 
     
    447471           "\t\t\t\t\t'bbackupquery usage' in the report.\n") 
    448472     
     473    stderr("  --sort\t\t\t\tSorts the file lists in verbose mode.\n") 
     474     
     475    stderr("  --debug\t\t\t\tEnables debug output.\n") 
     476 
    449477    stderr("  --verbose\t\t\t\tList every file that was backed up to\n"+\ 
    450478           "\t\t\t\t\tthe server, default is to just display\n"+\ 
     
    464492    stats = False 
    465493    sort = False 
    466  
     494    debug = False 
    467495    # Parse the options 
    468496    try: 
    469         opts, args = getopt.getopt(sys.argv[1:], "osrvhl:c:t:f:",  
     497        opts, args = getopt.getopt(sys.argv[1:], "dosrvhl:c:t:f:",  
    470498                        ["help", "logfile=", "configfile=","email-to=",  
    471                          "email-from=","rotate","verbose","stats","sort"]) 
     499                         "email-from=","rotate","verbose","stats","sort", 
     500                         "debug"]) 
    472501    except getopt.GetoptError: 
    473502        usage() 
     
    491520        elif(opt in ("--sort", "-o")): 
    492521            sort = True 
     522        elif(opt in ("--debug", "-d")): 
     523            debug = True 
    493524        elif(opt in ("--help", "-h")): 
    494525            usage() 
     
    497528    # Run the reporter 
    498529    bbr = BoxBackupReporter(configfile, logfile, email_to, email_from,  
    499                             rotate, verbose, stats, sort) 
     530                            rotate, verbose, stats, sort, debug) 
    500531    try: 
    501532        bbr.run() 
Note: See TracChangeset for help on using the changeset viewer.