Skip to content

Commit

Permalink
Update snapshot.php
Browse files Browse the repository at this point in the history
Old volume were not deleted.
  • Loading branch information
jbelien committed Feb 9, 2018
1 parent 6cf4e15 commit 7c340db
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
echo 'PROJECT: '.$p['id'].PHP_EOL;

if (isset($config['duration']) && !empty($config['duration'])) {
$list = $ovh->get('/cloud/project/'.$p['id'].'/snapshot');

$time = new DateTime();
$time->sub(new DateInterval($config['duration']));
echo 'Delete snapshots older than '.$time->format('Y-m-d H:i:s').PHP_EOL;

$count = 0;

$list = $ovh->get('/cloud/project/'.$p['id'].'/snapshot');
foreach ($list as $snapshot) {
$snapshot_time = new DateTime($snapshot['creationDate']);
if ($snapshot_time < $time) {
Expand All @@ -29,6 +29,17 @@
$count++;
}
}

$list = $ovh->get('/cloud/project/'.$p['id'].'/volume/snapshot');
foreach ($list as $snapshot) {
$snapshot_time = new DateTime($snapshot['creationDate']);
if ($snapshot_time < $time) {
$ovh->delete('/cloud/project/'.$p['id'].'/volume/snapshot/'.$snapshot['id']);
echo 'Delete snapshot "'.$snapshot['name'].'" ('.$snapshot_time->format('Y-m-d H:i:s').')'.PHP_EOL;
$count++;
}
}

echo sprintf('%d deleted snapshot(s)', $count).PHP_EOL;
}

Expand Down

0 comments on commit 7c340db

Please sign in to comment.