Created
May 14, 2012 16:35
-
-
Save adimircolen/2694963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/ruby | |
# | |
# Keeps backups for odrible for the last 7 days | |
# | |
# Assumes backups are stored in the dir referenced by the | |
# constant BACKUP_DIR. | |
# | |
# Assumes backup file names are in the formats '20101217002634.mysql-backup-sftp-odrible2.sql.gz.enc' | |
require 'date' | |
BACKUP_DIR = "/home/deploy/bkp/" | |
DAYS_TO_KEEP_BACKUP = 3 | |
# Get the file names of all odrible backups in BACKUP_DIR. | |
odrible_backup_files = Dir.glob(BACKUP_DIR + '*.mysql-backup-sftp-odrible*.sql.gz.enc') | |
odrible_backup_files.each do |file| | |
# Get the date in the filename in the format 20100920004501 and creates a new Date object. | |
date_string = file.match(/\d{14}/).to_s | |
unless date_string.empty? | |
year = date_string[0..3]; month = date_string[4..5]; day = date_string[6..7] | |
hour = date_string[8..9]; min = date_string[10..11]; sec = date_string[12..13] | |
date = Time.utc(year, month, day, hour, min, sec).send(:to_date) | |
# Delete the file if it is more than the specified number of days old. | |
File.delete(file) if date < (Date.today - DAYS_TO_KEEP_BACKUP + 1) | |
end | |
end | |
# Get the file names of all dengueville backups in BACKUP_DIR. | |
dv_backup_files = Dir.glob(BACKUP_DIR + 'dengueville_backup_*.tar.gz') | |
dv_backup_files.each do |file| | |
# Get the date in the filename in the format 20100920004501 and creates a new Date object. | |
date_string = file.match(/\d{14}/).to_s | |
unless date_string.empty? | |
year = date_string[0..3]; month = date_string[4..5]; day = date_string[6..7] | |
hour = date_string[8..9]; min = date_string[10..11]; sec = date_string[12..13] | |
date = Time.utc(year, month, day, hour, min, sec).send(:to_date) | |
# Delete the file if it is more than the specified number of days old. | |
File.delete(file) if date < (Date.today - 2) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment