本文整理汇总了Python中lib.db.DB.delete_run_versions方法的典型用法代码示例。如果您正苦于以下问题:Python DB.delete_run_versions方法的具体用法?Python DB.delete_run_versions怎么用?Python DB.delete_run_versions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.db.DB
的用法示例。
在下文中一共展示了DB.delete_run_versions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Run
# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import delete_run_versions [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
#.........这里部分代码省略.........