function deleteBackups($bucket) { global $s3; //delete the backup from 2 months ago $set_date = strtotime('-2 months'); //only if it wasn't the first of the month if ((int) date('j', $set_date) === 1) { return true; } //set s3 "dir" to delete $prefix = s3Path('', '', $set_date); //find files to delete $keys = $s3->getBucket($bucket, $prefix); //delete each key found foreach ($keys as $key => $meta) { $s3->deleteObject($bucket, $key); } //echo $prefix."\n"; //delete the backup from 2 weeks ago $set_date = strtotime('-2 weeks'); //only if it wasn't a saturday or the 1st if ((int) date('j', $set_date) === 1 || (string) date('l', $set_date) === "Saturday") { return true; } //set s3 "dir" to delete $prefix = s3Path('', '', $set_date); //find files to delete $keys = $s3->getBucket($bucket, $prefix); //delete each key found foreach ($keys as $key => $meta) { $s3->deleteObject($bucket, $key); } //debug //print_r($keys); //echo $prefix."\n"; }
function deleteDailyBackups() { global $s3; //delete the backup from 2 months ago $set_date = strtotime('-2 months'); //only if it wasn't the first of the month or a Saturday if ((int) date('j', $set_date) !== 1) { //set s3 "dir" to delete $prefix = s3Path('', '', $set_date, false); if (debug == true) { echo "Deleting backup from 2 months ago: " . $prefix . "\n"; } //delete each key found deletePrefix($prefix); } //delete the backup from 2 weeks ago $set_date = strtotime('-2 weeks'); //only if it wasn't a saturday or the 1st if ((int) date('j', $set_date) !== 1 && (string) date('l', $set_date) !== "Saturday") { $prefix = s3Path('', '', $set_date, false); if (debug == true) { echo "Deleting backup from 2 weeks ago: " . $prefix . "\n"; } deletePrefix($prefix); } }