-
-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathpopulate_dest.php
More file actions
33 lines (25 loc) · 1 KB
/
populate_dest.php
File metadata and controls
33 lines (25 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?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');
}
mkdir($destDir);
touch($destDir . '/backup.marker');
$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);
}