Documented backup expiration strategy and added test file
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
test.sh
|
test.sh
|
||||||
*~
|
*~
|
||||||
|
tests/TestDest/
|
||||||
|
tests/TestSource/
|
||||||
|
|||||||
@@ -69,11 +69,13 @@ On macOS, it has a few disadvantages compared to Time Machine - in particular it
|
|||||||
|
|
||||||
## Backup expiration logic
|
## Backup expiration logic
|
||||||
|
|
||||||
The script automatically deletes old backups using the following logic:
|
Backup sets are automatically deleted following a simple expiration strategy defined with the `--strategy` flag. This strategy is a series of time intervals with each item being defined as `x:y`, which means "after x days, keep one backup every y days". The default strategy is `1:1 30:7 365:30`, which means:
|
||||||
- Within the last 24 hours, all the backups are kept.
|
|
||||||
- Within the last 31 days, the most recent backup of each day is kept.
|
- After **1** day, keep one backup every **1** day (**1:1**).
|
||||||
- After 31 days, only the most recent backup of each month is kept.
|
- After **30** days, keep one backup every **7** days (**30:7**).
|
||||||
- Additionally, if the backup destination directory is full, the oldest backups are deleted until enough space is available.
|
- After **365** days, keep one backup every **30** days (**365:30**).
|
||||||
|
|
||||||
|
Before the first interval (i.e. by default within the first 24h) it is implied that all backup sets are kept. Additionally, if the backup destination directory is full, the oldest backups are deleted until enough space is available.
|
||||||
|
|
||||||
## Exclude file
|
## Exclude file
|
||||||
|
|
||||||
@@ -110,7 +112,7 @@ The script creates a backup in a regular directory so you can simply copy the fi
|
|||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2013-2017 Laurent Cozic
|
Copyright (c) 2013-2018 Laurent Cozic
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// This PHP script can be used to test the expiration strategy.
|
||||||
|
// It is going to populate a directory with fake backup sets (directories named Y-m-d-His) over several months.
|
||||||
|
// Then the backup script can be run on it to check what directories are going to be deleted.
|
||||||
|
|
||||||
|
// rm -rf ./tests/TestDest/201* && php ./tests/populate_dest.php && ./rsync_tmbackup.sh ./tests/TestSource/ ./tests/TestDest/
|
||||||
|
|
||||||
|
$baseDir = dirname(__FILE__);
|
||||||
|
$destDir = $baseDir . '/TestDest';
|
||||||
|
|
||||||
|
$backupsPerDay = 2;
|
||||||
|
$totalDays = 500;
|
||||||
|
|
||||||
|
$intervalBetweenBackups = null;
|
||||||
|
if ($backupsPerDay === 1) {
|
||||||
|
$intervalBetweenBackups = 'PT1D';
|
||||||
|
} else if ($backupsPerDay === 2) {
|
||||||
|
$intervalBetweenBackups = 'PT12H';
|
||||||
|
} else {
|
||||||
|
throw new Exception('Not implemented');
|
||||||
|
}
|
||||||
|
|
||||||
|
$d = new DateTime();
|
||||||
|
$d->sub(new DateInterval('P' . $totalDays . 'D'));
|
||||||
|
|
||||||
|
for ($i = 0; $i < $backupsPerDay * $totalDays; $i++) {
|
||||||
|
$d->add(new DateInterval($intervalBetweenBackups));
|
||||||
|
mkdir($destDir . '/' . $d->format('Y-m-d-His'), 0777, true);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user