Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $week_offset = date("Y-m-d 12:00:00", time() - 60 * 60 * 24 * 7);
- $month_offset = date("Y-m-d 12:00:00", time() - 60 * 60 * 24 * 30);
- $three_month_offset = date("Y-m-d 12:00:00", time() - 60 * 60 * 24 * 90);
- $table = get_table(1);
- $del_count = 0;
- $three_month_del_count = array();
- $backup_time_last = array();
- $backup_count_all = array();
- $result_count_all = sql_query("SELECT * FROM " . DATA_TABLE . "1 WHERE f61 IN ('ежедневный', 'апргрейд') AND f321 NOT LIKE '%free%' Order by add_time desc");
- while ($row_count_all = sql_fetch_assoc($result_count_all)) {
- if (!$backup_count_all[$row_count_all['f41']]) {
- $backup_count_all[$row_count_all['f41']] = 1;
- } else {
- $backup_count_all[$row_count_all['f41']]++;
- }
- }
- $result = sql_query("SELECT * FROM " . DATA_TABLE . "1 WHERE f61 IN ('ежедневный', 'апргрейд') and add_time<'" . form_sql($week_offset) . "' AND f321 NOT LIKE '%free%' Order by add_time desc");
- while ($line = sql_fetch_assoc($result)) {
- $delete = 'удалять';
- $backup_time = strtotime($line['add_time']);
- if (!$three_month_del_count[$line['f41']]) {
- $three_month_del_count[$line['f41']] = 0;
- }
- if (!$backups_last_month_count[$line['f41']]) {
- $backups_last_month_count[$line['f41']] = 0;
- }
- if ($backup_count_all[$line['f41']] <= 14) {
- $delete = 'оставляем';
- }
- if (date("w", $backup_time) == 1) {
- // Оставляем бэкапы Последний месяц, раз в неделю 3 штуки
- if ($backup_time > strtotime($month_offset) && $backups_last_month_count[$line['f41']]<3) {
- $delete = 'оставляем';
- $backups_last_month_count[$line['f41']]++;
- } elseif (($backup_time > strtotime($three_month_offset)) && ($three_month_del_count[$line['f41']] < 8)) {
- // Проверяем 8 так как в 2-х месяцах оставшихся 8 недель
- // Оставляем бэкапы Последние 3 месяца, каждые 2 недели 4 штуки
- $three_month_del_count[$line['f41']]++;
- if ($backup_time_last[$line['f41']]) {
- if (($backup_time_last[$line['f41']] - $backup_time) > 864000) {
- $delete = 'оставляем';
- }
- } // оставляем если промежуток между предыдущим больше 10 дней
- if (($three_month_del_count[$line['f41']] % 2) == 0) {
- $delete = 'оставляем';
- } // оставляем каждый второй
- }
- }
- $backup_time_last[$line['f41']] = $backup_time;
- // удалить
- if ($delete == 'удалять') {
- drop_files_by_line($table, $line);
- sql_query("DELETE FROM " . DATA_TABLE . "1 WHERE id=" . intval($line['id']));
- $del_count++;
- }
- }
- echo "Deleted $del_count backups";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement