def test_toDateTime(self):
     dt = fn.toDateTime("2012-05-18-160013")
     self.assertEqual(dt.year, 2012)
     self.assertEqual(dt.month, 5)
     self.assertEqual(dt.day, 18)
     self.assertEqual(dt.hour, 16)
     self.assertEqual(dt.minute, 0)
     self.assertEqual(dt.second, 13)
Example #2
0
def _getExtraDailyBackups(backups):
    """
    Returns the extra backups that appear more than once in the
    same day.
    """
    sortedBackups = [b for b in reversed(sorted(backups))]
    previous = None
    current = None
    index = 0
    results = []

    while index < len(sortedBackups):
        current = fn.toDateTime(sortedBackups[index])
        if previous is not None:
            if current.day == previous.day:
                results.append(sortedBackups[index])
        previous = fn.toDateTime(sortedBackups[index])
        index += 1
    return results
Example #3
0
def info(args, settings):
    """
    Main function for the info option.
    """
    backupHome = fn.getBackupHome(settings.backupLocation, settings.hostName)
    backupCount = len(fn.getBackups(backupHome))
    dtFormat = "%m/%d/%Y %H:%M:%S"
    lastBackupRan = fn.toDateTime(
        fn.getLatestBackup(backupHome)).strftime(dtFormat)
    driveUsagePercentage = fn.getDriveUsagePercentage(backupHome)
    fmt = "{0:<20} {1}"

    print(fmt.format("Backup location:", settings.backupLocation))
    print(fmt.format("Host Name:", settings.hostName))
    print(fmt.format("Number of Backups:", backupCount))
    print(fmt.format("Last Backup Ran:", lastBackupRan))
    print(fmt.format("Drive Capacity:", "{0}%".format(driveUsagePercentage)))
Example #4
0
def _getExtraWeeklyBackups(backups):
    """
    Returns the backups that appear within one week of each other.
    """
    oneWeek = timedelta(7)
    previous = datetime.now().date()
    results = []

    for backup in sorted(backups):
        current = fn.toDateTime(backup).date()
        diff = current - previous

        # If the difference is a negative number, it's the first
        # backup and we can skip it
        if diff.days < 0:
            previous = current
            continue

        if diff < oneWeek:
            results.append(backup)
        else:
            previous = current
    return results
Example #5
0
def _catagorize(backups, now=datetime.now()):
    """
    Returns the backups in their respective categories of today,
    daily and weekly.
    """
    oneDay = timedelta(1)
    thirtyOneDays = timedelta(31)
    items = {
        "today": [],
        "daily": [],
        "weekly": []}

    for backup in backups:
        backupDate = fn.toDateTime(backup)
        diff = now - backupDate

        if diff > oneDay and diff < thirtyOneDays:
            items["daily"].append(backup)
        elif diff > thirtyOneDays:
            items["weekly"].append(backup)
        else:
            items["today"].append(backup)
    return items
Example #6
0
 def isOld(backup):
     dt = fn.toDateTime(backup)
     expire = datetime.now() - timedelta(days=keepDays)
     return dt <= expire