本文整理汇总了Python中lib.db.DB.save_message方法的典型用法代码示例。如果您正苦于以下问题:Python DB.save_message方法的具体用法?Python DB.save_message怎么用?Python DB.save_message使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.db.DB
的用法示例。
在下文中一共展示了DB.save_message方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wiz_execute
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import save_message [as 别名]
def wiz_execute(wiz):
db = DB()
config = Config.get_config()
backups = config.backups.keys()
backups.sort()
for name in backups:
if wiz.fields[name].value:
# Get the backup object and store
backup = config.backups[name]
store = config.storage[backup.store].copy()
# For each run on the store
with ProgressDialog(wiz, _("Connecting"), _("Connecting to the store.\nPlease wait...")):
store.connect()
prog_dlg = ProgressDialog(wiz, _("Loading"), _("Retrieving data from store.\nPlease wait..."))
prog_dlg.Show()
try:
try:
runs = store.list(backup.name)
except:
# If it fails, there were no backup runs
runs = []
runs.sort()
for run in runs:
(date, type) = run.split(" ")
date = datetime.strptime(date, const.DateTimeFormat)
db.start_run(backup.name, store.name, type, date)
db.save_message(_("Database rebuild started"))
try:
store_size, _file_sizes, nfiles, nfolders = recover_run(config, db, backup, store, run)
db.save_message(_("Database rebuild complete"))
db.update_run_stats(store_size, nfiles, nfolders, backup.include_packages, "")
db.update_run_status(const.StatusSuccess)
except Exception as e:
msg = _("Database rebuild failed. {error}").format(error=str(e))
db.save_message(msg)
db.update_run_status(const.StatusFailed)
dlg.Warn(wiz, msg, _("Error"))
return
finally:
prog_dlg.Destroy()
store.disconnect()
wiz.parent.force_rebuild()
# Now tell app about change.
app.broadcast_update()
dlg.Info(wiz, _("Your backup files database has been rebuilt.\nYou can now view your file and backup history."), _("Rebuild"))
示例2: Tester
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import save_message [as 别名]
#.........这里部分代码省略.........
# # restore as at full date
# # restore as at incr date
#
#
# except Exception as e:
# log.error("Test run failed: %s" % str(e))
# finally:
# self.cleanup()
log.info("********Success")
def send_email(self, result, error_message=None):
'''
Send a message to the appropriate users.
If result is False (failure) then error message will contain the reason.
@param result:
@param error_message:
'''
log.debug("send_email: ", result, error_message)
if result:
message_text = "Test to folder %s completed." % (self.test_folder)
subject = "Test Completed"
else:
message_text = "Test FAILED\n\nERROR: %s" % (error_message)
subject = "Test FAILED"
log.debug("Starting mail send")
try:
sendemail.sendemail(subject, message_text)
except Exception as e:
self.db.save_message("Unable to email results: %s" % str(e))
log.trace("send_email completed")
def run_cycle_test(self):
options = BlankClass()
options.dry_run = False
options.message = False
options.email = False
options.shutdown = False
options.norecurse = False
# Run a full backup
b = Run("testbackup1", const.FullBackup, options)
b.run()
# Run a full backup
b = Run("testbackup2", const.FullBackup, options)
b.run()
# Now restore two files, one that will be on each store.
restore_file1 = os.path.join(self.files_folder, "dir1", "f2.mp3")
dest_file1 = os.path.join(self.restore_folder, restore_file1[1:])
restore_file2 = os.path.join(self.files_folder, "dir2", "f3.exe")
dest_file2 = os.path.join(self.restore_folder, restore_file2[1:])
restore_file3 = os.path.join(self.files_folder, "dir3", "f4.txt")
dest_file3 = os.path.join(self.restore_folder, restore_file3[1:])
r = Restore(self.restore_folder, [restore_file1, restore_file2, restore_file3],
datetime.now(), options)
r.run()
for path in [dest_file1, dest_file2, dest_file3]:
if not os.path.exists(path):
raise Exception("File %s was not restored" % path)
if open(path).read() != self.teststring1:
示例3: Run
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import save_message [as 别名]
class Run():
def __init__(self, name, type, options):
'''
Prepare to run a backup event
@param name: name of the backup
@param type: type (Full/Incr)
@param type: dry_run
If dry_run is True, then we will print the files we *would have* backed
up to stdout.
'''
self.type = type
self.dry_run = options.dry_run
self.options = options
self.config = Config.get_config()
try:
self.backup = self.config.backups[name]
except:
raise Exception(_("Backup is missing or corrupt. Please reconfigure backup."))
try:
# Get a fresh store (a copy of the config version
self.store = self.config.storage[self.backup.store].copy()
except:
raise Exception(_("Storage definition is missing. Please reconfigure backup."))
self.db = DB()
self.start_time = None
self.nfiles = None
self.nfolders = None
self.bytes = None
self.run_id = None
self.backup_folder = None
# Make sure there are no other backups running of this name
self.lock = locking.InterProcessLock(name="Vault-%s" % self.backup.name)
# Build a quick file exclusion list, to speed up exclusion checking
self.excl_ext = self.build_excl_exts()
log.debug("Exclusion List:", ",".join(self.excl_ext))
def run(self):
'''
Execute the backup
'''
try:
self.lock.acquire()
except:
msg = _("Backup '%s' is already running. New backup run cannot start") \
% (self.backup.name)
if not self.dry_run:
# Since this is a real backup, we create the run, write to the log and fail immediately.
self.db.start_run(self.backup.name, self.backup.store, self.type, datetime.now())
self.db.save_message(msg)
self.db.update_run_status(const.StatusFailed)
else:
# We dont need to do anything for a dry run. The message will
# be returned to the user.
pass
raise Exception(msg)
# We have the lock now...
try:
self.orig_type = self.type
self.check_old_backups()
self.do_backup()
finally:
self.lock.release()
def check_old_backups(self):
'''
We have got the lock, but if there was a crash, there may be a "running"
state backup left behind. Note that we *know* its not running because
the lock is gone.
Check for it and fail it if there is.
'''
log.debug("Checking for dead backups")
runs = self.db.runs(self.backup.name)
runs = [run for run in runs if run.status == const.StatusRunning]
# It looks like there is a run that is still running.
for run in runs:
log.warn("A prior run crashed. Cleaning up %s/%s" % (run.name, run.start_time_str))
# Get the store
log.debug("Attempting to delete remote run data")
try:
self.store.delete_run_data(run)
except:
pass
# 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)
# Update the status
#.........这里部分代码省略.........