MCPcopy Create free account
hub / github.com/ActiveState/code / GetLatestBackup

Function GetLatestBackup

recipes/Python/578977_Python_SQLSMO_/recipe-578977.py:55–69  ·  view source on GitHub ↗

Returns folder contents sorted by modified date Sample use: backupfolder = r'\\SERVERNAME\SQLBackups1\SQLBackupUser' This brings all files lst = GetLatestBackup(backupfolder) Here we bring a subset using filter string filter = '\DATABASE_*.bak' lst = GetLatestBackup(

(dirpath, filter='\*.*')

Source from the content-addressed store, hash-verified

53
54
55def GetLatestBackup(dirpath, filter='\*.*'):
56 """
57 Returns folder contents sorted by modified date
58 Sample use:
59 backupfolder = r'\\SERVERNAME\SQLBackups1\SQLBackupUser'
60 This brings all files
61 lst = GetLatestBackup(backupfolder)
62 Here we bring a subset using filter string
63 filter = '\DATABASE_*.bak'
64 lst = GetLatestBackup(backupfolder, filter)
65 """
66
67 a = [s for s in glob.glob(dirpath + filter) if os.path.isfile(os.path.join(dirpath, s))]
68 a.sort(key=lambda s: os.path.getmtime(os.path.join(dirpath, s)))
69 return a
70
71def DeleteOlderFiles(workfolder, days):
72 """

Callers 3

BuildTlogSQLFunction · 0.85
recipe-578977.pyFile · 0.85
ActionParsingFunction · 0.85

Calls 3

isfileMethod · 0.80
joinMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected