Действия
Archive-rotate » История » Редакция 2
« Предыдущее |
Редакция 2/3
(Разница(diff))
| Следующее »
Андрей Волков, 2013-03-22 15:07
Ротация архивов по расписанию¶
pg_cleanup_backedup_archives.sh¶
#!/bin/bash DAYS_BEFORE_LAST_BACKUP=3 if [ -z "${2}" ]; then echo "USEAGE: ${0##*/} /path/to/pg_archive backup-report.file" >&2 exit 1 fi PG_ARCHIVE_DIRECTORY="${1}" BACKUP_REPORT_FILE="${2}" if [ ! -w "${PG_ARCHIVE_DIRECTORY}" ]; then echo "Archive directory '${PG_ARCHIVE_DIRECTORY}' is not writable" >&2 exit 1 fi if [ ! -e "${BACKUP_REPORT_FILE}" ]; then echo "File '${BACKUP_REPORT_FILE}' not found" >&2 exit 1 fi SEARCH_DAYS_AGO=$[($(date +'%s')-$(stat -c '%Y' "${BACKUP_REPORT_FILE}"))/24/3600+${DAYS_BEFORE_LAST_BACKUP}] || exit 1 OLD_BACKUPS=$(find "${PG_ARCHIVE_DIRECTORY}" -type f -name "*.backup" -mtime +"${SEARCH_DAYS_AGO}" -printf '%f\n') || exit 1 if [ -n "${OLD_BACKUPS}" ]; then pg_archivecleanup "${PG_ARCHIVE_DIRECTORY}" $(echo "${OLD_BACKUPS}" |sort | tail -n 1) || exit 1 for NAME in ${OLD_BACKUPS}; do rm -f "${PG_ARCHIVE_DIRECTORY}/${NAME}" || exit 1 done fi
Обновлено Андрей Волков почти 12 года назад · 3 изменени(я, ий)