コード例 #1
0
def run_backup():
    """
    Main method that performs the backup.
    """
    commandArgs = getArgs()
    if commandArgs.version:
        print("caatinga version: " + __version__)
        exit(0)

    settings = fn.getSettingsInstance(commandArgs)
    lockFileName = settings.hostName + "-caatinga"
    SettingsValidator().validate(settings)
    bkHome = fn.getBackupHome(settings.backupLocation, settings.hostName)
    lockFile = backup.getLockFile("/tmp", lockFileName)
    outWriter = fn.getOutputWriter(commandArgs.verbose)
    previousBackup = os.path.realpath(fn.getLatestLink(bkHome))

    fn.runHooks(settings.preBackupHooksDir)
    checkForRegisterOption(settings, commandArgs, bkHome)
    insureBackupLocationIsRegistered(
        settings.backupLocation,
        settings.hostName)
    lock(lockFile)
    runNonBackupFunctions(bkHome, settings, commandArgs, outWriter, lockFile)
    executeBackup(bkHome, previousBackup, settings, outWriter, lockFile)
    runMaintenanceFunctions(bkHome, settings, outWriter)
    fn.runHooks(settings.postBackupHooksDir)
コード例 #2
0
def runWithHooks(optionFn, args, settings):
    """
    Wrap the provided option call with the pre and post restore hooks.
    """
    fn.runHooks(settings.preRestoreHooksDir)
    optionFn(args, settings)
    fn.runHooks(settings.postRestoreHooksDir)
コード例 #3
0
def runNonBackupFunctions(bkHome, settings, commandArgs, outWriter, lockFile):
    """
    Execute functions that do not pertain to actually performing a backup and
    are more intended on pre-backup conditions.
    """
    try:
        checkForDeleteOldest(commandArgs, bkHome)
        markPartialBackupForDeletion(bkHome)
        checkForClean(commandArgs, bkHome, outWriter)
    except CleanExitException:
        fn.runHooks(settings.postBackupHooksDir)
        backup.removeLockFile(lockFile)
        raise