pyExpireBackups API Documentation
expire
Created on 2022-04-01
@author: wf
BackupFile
a Backup file which is potentially to be expired
Source code in expirebackups/expire.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
__init__(filePath)
constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filePath(str)
|
the filePath of this backup File |
required |
Source code in expirebackups/expire.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
__str__()
return a string representation of me
Source code in expirebackups/expire.py
50 51 52 53 54 55 |
|
delete()
delete my file
Source code in expirebackups/expire.py
135 136 137 138 139 140 |
|
getAgeInDays()
get the age of this backup file in days
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
the number of days this file is old |
Source code in expirebackups/expire.py
114 115 116 117 118 119 120 121 122 123 |
|
getIsoDateOfModification()
get the data of modification as an ISO date string
Returns:
Name | Type | Description |
---|---|---|
str |
an iso representation of the modification date |
Source code in expirebackups/expire.py
125 126 127 128 129 130 131 132 133 |
|
getMarker()
get my marker
Returns:
Name | Type | Description |
---|---|---|
str |
a symbol ❌ if i am to be deleted a ✅ if i am going to be kept |
Source code in expirebackups/expire.py
57 58 59 60 61 62 63 64 65 |
|
getSize(size)
classmethod
get my Size in human readable terms
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size(float)
|
Size in Bytes |
required |
Returns:
Name | Type | Description |
---|---|---|
Tuple |
(float, str, float)
|
the size, unit and factor of the unit e.g. 3.2, "KB", 1024 |
Source code in expirebackups/expire.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
getSizeString(size)
classmethod
get my Size in human readable terms as a s
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size(float)
|
Size in Bytes |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
a String representation |
Source code in expirebackups/expire.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
getStats()
get the datetime when the file was modified
Returns:
Name | Type | Description |
---|---|---|
datetime |
Tuple[datetime, float]
|
the file modification time |
Source code in expirebackups/expire.py
102 103 104 105 106 107 108 109 110 111 112 |
|
Expiration
Expiration pattern
Source code in expirebackups/expire.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
__init__(days=defaultDays, weeks=defaultWeeks, months=defaultMonths, years=defaultYears, minFileSize=defaultMinFileSize, debug=False)
constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
days(float)
|
how many files to keep for the daily backup |
required | |
weeks(float)
|
how many files to keep for the weekly backup |
required | |
months(float)
|
how many files to keep for the monthly backup |
required | |
years(float)
|
how many files to keep for the yearly backup |
required | |
debug(bool)
|
if true show debug information (rule application) |
required |
Source code in expirebackups/expire.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
|
applyRules(backupFiles, verbose=True)
apply my expiration rules to the given list of backup Files
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backupFiles(list)
|
the list of backupFiles to apply the rules to |
required | |
verbose(debug)
|
if true show what the rules are doing |
required |
Returns: list: the sorted and marked list of backupFiles
Source code in expirebackups/expire.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
|
getNextRule(ruleIter, prevFile, verbose)
get the next rule for the given ruleIterator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ruleIter(Iter)
|
Iterator over ExpirationRules |
required | |
prevFile(BackupFile)
|
the previousFile to take into account / reset/anchor the rule with |
required | |
verbose(bool)
|
if True show a message that the rule will be applied |
required |
Returns: ExpirationRule: the next ExpirationRule
Source code in expirebackups/expire.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
ExpirationRule
an expiration rule keeps files at a certain
Source code in expirebackups/expire.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
__init__(name, freq, minAmount)
constructor
name(str): name of this rule freq(float): the frequency) in days minAmount(int): the minimum of files to keep around
Source code in expirebackups/expire.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
apply(file, prevFile, debug)
apply me to the given file taking the previously kept File prevFile (which might be None) into account
Args:
file(BackupFile): the file to apply this rule for
prevFile(BackupFile): the previous file to potentially take into account
debug(bool): if True show debug output
Source code in expirebackups/expire.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
reset(prevFile)
reset my state with the given previous File
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prevFile
|
BackupFile
|
BackupFile - the file to anchor my startAge with |
required |
Source code in expirebackups/expire.py
163 164 165 166 167 168 169 170 171 172 173 174 |
|
ExpireBackups
Bases: object
Expiration of Backups - migrated from com.bitplan.backup java solution
Source code in expirebackups/expire.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
__init__(rootPath, baseName=None, ext=None, expiration=None, dryRun=True, debug=False)
Constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rootPath(str)
|
the base path for this backup expiration |
required | |
baseName(str)
|
the basename to filter for (if any) |
required | |
ext(str)
|
file extensions to filter for e.g. ".tgz" (if any) |
required | |
expiration(Expiration)
|
the Expiration Rules to apply |
required | |
dryRun(bool)
|
donot delete any files but only show deletion plan |
required |
Source code in expirebackups/expire.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
|
createTestFile(ageInDays, baseName=None, ext='.tst')
classmethod
create a test File with the given extension and the given age in Days
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ageInDays(float)
|
the age of the file in days |
required | |
baseName(str)
|
the prefix of the files (default: None) |
required | |
ext(str)
|
the extension to be used - default ".tst" |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
the full path name of the testfile |
Source code in expirebackups/expire.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
createTestFiles(numberOfTestfiles, baseName='expireBackupTest', ext='.tst')
classmethod
create the given number of tests files
Parameters:
Name | Type | Description | Default |
---|---|---|---|
numberOfTestfiles(int)
|
the number of files to create |
required | |
baseName(str)
|
the prefix of the files (default: '') |
required | |
ext(str)
|
the extension of the files (default: '.tst') |
required |
Returns:
Name | Type | Description |
---|---|---|
tuple |
(str, list)
|
the path of the directory where the test files have been created |
and a list of BackupFile files |
Source code in expirebackups/expire.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
doexpire(withDelete=False, show=True, showLimit=None)
expire the files in the given rootPath
withDelete(bool): if True really delete the files show(bool): if True show the expiration plan showLimit(int): if set limit the number of lines to display
Source code in expirebackups/expire.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
getBackupFiles()
get the list of my backup Files
Source code in expirebackups/expire.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|
main(argv=None)
main program.
Source code in expirebackups/expire.py
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
|
version
Created on 2022-04-01
@author: wf
Version
Bases: object
Version handling for pyExpireBackups
Source code in expirebackups/version.py
8 9 10 11 12 13 14 15 16 17 |
|