def init_logfile(self):
        """
		Make sure we can create and write to the logfile
		"""
        if os.path.exists(self.logfile):
            # move the logfile aside and compress it
            bz_file = bz2.BZ2File("%s.bz2" % self.logfile, 'w')
            log = open(self.logfile, 'r')
            bz_file.writelines(log.readlines())
            log.close()
            bz_file.close()
        #print "Logging output to %s" % self.logfile
        date = dateutil.get_datetime()
        time = dateutil.get_datetime(1)
        new_file = open(self.logfile, 'w')
        new_file.write(
            "#------------------------- RSYNC LOG -------------------------\n#\n"
        )
        new_file.write("#%12s: %s\n" % ('Date', date))
        new_file.write("#%12s: %s\n" % ('Time', time))
        new_file.write("#%12s: %s\n" % ('Source', self.source))
        new_file.write("#%12s: %s\n" % ('Destination', self.destination))
        new_file.write("#%12s: %s\n" % ('Command', self.command))
        new_file.write("#%12s: %s\n\n" % ('Logfile', self.logfile))
        new_file.close()
        return True
Beispiel #2
0
def _run_restore(csf):
    """
	Run the tina_restore and handle 
	nay errors that may occur.
	"""
    try:
        Tina.restore(path_folder=csf.data['real_path'],
                     application=csf.data['real_application'],
                     path_dest=csf.temp_restore_dir,
                     dry_run=options.dry_run)
    except Exception, error:
        subject = "Atempo Consolidate Error"
        message = 'Restore Failed at: %s' % (dateutil.get_datetime(23))
        send_email(subject, message, objs=[csf], error_msg=error)
        # pass through the exception
        raise
Beispiel #3
0
 for entry in queue:
     appl = Tina().APPLICATIONS[entry['application']]
     tmp_path_dest = "%s/.restore" % (entry['path_dest'])
     if not os.path.exists(tmp_path_dest):
         os.makedirs(tmp_path_dest)
     print "  Restoring (%s of %s): %s" % (i, len(queue), entry['target'])
     try:
         #print "Tina.restore(path_folder=%s,application=%s,path_dest=%s,strat='%s')" % (entry['path'],appl,tmp_path_dest,strat)
         Tina.restore(path_folder=entry['path'],
                      application=appl,
                      path_dest=tmp_path_dest,
                      strat=strat)
     except Exception, error:
         message = 'Restore of: %s\n' % entry['path']
         message += 'Resting to: %s\n' % entry['target']
         message += 'Failed at: %s' % (dateutil.get_datetime(23))
         message += '\nError message:\n'
         for line in error.message.split("\n"):
             message += '%s\n' % line
         if options.email:
             send_email('Failed', message)
         #else:
         #	traceback.print_exc()
         #	print message
         print "\nError running tina command:"
         print "%s\n" % message
     else:
         # move the restored file out of the .restore directory
         source = "%s/%s" % (tmp_path_dest, entry['filename'])
         target = entry['target']
         #print "os.rename(",source,target