''' import json, sys from verify import Verify if len(sys.argv) > 1: RUNPATH = sys.argv[1] else: RUNPATH = '../bin' LOGPATH = RUNPATH + '/logs' CONFIGFILE = RUNPATH + '/DAM.config' config_data= open(CONFIGFILE).read() data = json.loads(config_data) USERLIST = [json.dumps(u).strip('"') for u in data["userlist"]] RULELIST = [json.dumps(r).strip('"') for r in data["rulelist"]] SERVER = json.dumps(data["server"]).strip('"') print 'Runpath: ', RUNPATH print 'Logpath: ', LOGPATH print 'Server from config file: ', SERVER print 'Userlist from config file: ', USERLIST print 'Rulelist from config file: ', RULELIST v = Verify(LOGPATH, SERVER) v.run(USERLIST, RULELIST)
def do_backup(self) : self.start_time = datetime.now() self.nfiles = 0 self.nfolders = 0 self.bytes = 0 success = False message = "" self.backup_folder = os.path.join(self.backup.name, self.start_time.strftime(const.DateTimeFormat) + " " + self.type) if not self.dry_run: self.run_id = self.db.start_run(self.backup.name, self.backup.store, self.type, self.start_time) msg = _("Backup {server}/{backup}/{type} beginning").format( server=utils.get_hostname(), backup=self.backup.name, type=self.type) if self.dry_run: msg += _(" (Dry Run)") log.info(msg) self.db.save_message(msg) if self.orig_type != self.type: # The backup type was switched self.db.save_message(_("NOTE: Backup type switched to {newtype} from {oldtype}").format( newtype=self.type, oldtype=self.orig_type)) # After here we have a run set up in the database, and can begin logging errors. try: # Check that if ENCRYPTION is enabled, that there is a password defined. if self.backup.encrypt and not self.config.data_passphrase: raise Exception("Backup encryption required, but no passphrase has been configured. Backup cancelled.") self.prepare_store() # Prepare output/destinations/encryption self.prepare_output() try: # Now we actually DO the backup, for each listed folder for folder in self.backup.include_folders: self.recursive_backup_folder(folder) log.debug("Committing saved fs entries...") self.db.fs_saved_commit() log.debug("Closing...") self.close_output(success=True) #raise Exception("Test Exception") except Exception as e: log.warn("Exception during backup:", str(e)) # We are going to fail. But we need to try and close # whatever we can. Closing may fail, but in this case # we ignore that error. try: self.close_output(success=False) except: pass raise e if self.backup.verify and not self.dry_run: log.info("Starting verify phase") msg = _("Backup {server}/{backup}/{type} verification starting").format( server=utils.get_hostname(), backup=self.backup.name, type=self.type) self.db.save_message(msg) v = Verify(self.backup.name, self.start_time) v.run() msg = _("Backup {server}/{backup}/{type} verification succeeded").format( server=utils.get_hostname(), backup=self.backup.name, type=self.type) self.db.save_message(msg) # self.do_verify() # Messaging... # If its a dry run, the command line specifies messaging. # Otherwise both the command line AND backup spec do. if not self.dry_run: self.db.update_run_status(const.StatusSuccess) message = _("Backup {server}/{backup}/{type} completed").format( server=utils.get_hostname(), backup=self.backup.name, type=self.type) if self.dry_run: message += " " + _("(Dry Run)") success = True if not self.dry_run: self.db.save_message(message) except Exception as e: log.error("Exception in backup. Recording. ", e) message = _("Backup {server}/{backup}/{type} failed. {error}").format( server=utils.get_hostname(), backup=self.backup.name, type=self.type, error=str(e)) success = False if not self.dry_run: self.db.update_run_status(const.StatusFailed) # After a failed backup - we must remove the backup data because it # cannot be trusted. run = self.db.run_details(self.run_id) # Delete the remote data log.debug("Attempting to delete remote run data") self.store.delete_run_data(run) # Delete the entries in the database (but not the failed run itself) # This means the messages will persist, so we can see the usage. log.debug("Attempting to delete DB run data") self.db.delete_run_versions(self.run_id) self.db.save_message(message) if self.options.message or (self.backup.notify_msg and not self.dry_run): try: from lib.dlg import Notify Notify(const.AppTitle, message) except Exception as e: # This one is not really an error... there is probably no-one logged in. msg = _("Unable to send notification message (no-one logged in)") if not self.dry_run: self.db.save_message(message) log.info(msg) if self.options.email or (self.backup.notify_email and not self.dry_run): try: self.send_email(success, message) except Exception as e: msg = _("Unable to email notification message: {error}").format( error=str(e)) if not self.dry_run: self.db.save_message(message) log.error(msg) if self.options.shutdown or (self.backup.shutdown_after and not self.dry_run): try: cmd = ["zenity", "--question", "--ok-label", _("Shutdown Now"), "--cancel-label", _("Cancel Shutdown"), "--text", _("Backup {backup} complete. Computer will shut down in 2 minutes").format(backup=self.backup.name), "--timeout", "120"] status = subprocess.call(cmd) log.debug("Shutdown query. status=%d" % status) if status == 0 or status == 5: print("Running shutdown") subprocess.Popen(["shutdown", "-P", "now"]) print("Done running shutdown") except Exception as e: msg = _("Unable to shutdown PC: {error}").format( error=str(e)) if not self.dry_run: self.db.save_message(message) log.error(msg)