Skip to content

Commit

Permalink
change controller to use compressed file format
Browse files Browse the repository at this point in the history
  • Loading branch information
lazylester committed Mar 21, 2013
1 parent 3d8d68c commit 169332f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/get_back/backups_controller.rb
Expand Up @@ -59,7 +59,7 @@ def show
# overwrites the active database with the file passed in # overwrites the active database with the file passed in
def write_db(backfile) def write_db(backfile)
if backfile.valid? if backfile.valid?
ApplicationDatabase.restore_from_file(backfile) # returns false if restore fails ApplicationDatabase.restore_from_zipfile(backfile) # returns false if restore fails
else else
flash[:error] = "File name does not have correct format.<br/>Are you sure it's a database backup file?<br/>Database was not restored." flash[:error] = "File name does not have correct format.<br/>Are you sure it's a database backup file?<br/>Database was not restored."
false false
Expand Down
12 changes: 6 additions & 6 deletions app/models/backup_file.rb
Expand Up @@ -7,7 +7,7 @@ class BackupFile


# either returns all backup files (for index action) or the single file whose filename is passed-in (e.g. backups_2009-08-16_07-50-26_development_dump) # either returns all backup files (for index action) or the single file whose filename is passed-in (e.g. backups_2009-08-16_07-50-26_development_dump)
def self.find(arg) def self.find(arg)
backup_files = Dir.glob(File.join(BACKUP_DIR,"*.sql")) backup_files = Dir.glob(File.join(BACKUP_DIR,"*.sql.gz"))


case arg case arg
when :all when :all
Expand Down Expand Up @@ -55,22 +55,22 @@ def destroy
def initialize(attributes={}) def initialize(attributes={})
datestamp = "backups_"+Time.now.strftime("%Y-%m-%d_%H-%M-%S") datestamp = "backups_"+Time.now.strftime("%Y-%m-%d_%H-%M-%S")
Dir.mkdir(BACKUP_DIR) unless File.exists?(BACKUP_DIR) Dir.mkdir(BACKUP_DIR) unless File.exists?(BACKUP_DIR)
new_filename = BACKUP_DIR + "#{datestamp}_#{Rails.env}_dump.sql" new_filename = BACKUP_DIR + "#{datestamp}_#{Rails.env}_dump.sql.gz"
@file = attributes[:filename].nil? ? File.new(new_filename, "w") : File.new(attributes[:filename]) @file = attributes[:filename].nil? ? File.new(new_filename, "w") : File.new(attributes[:filename])
end end


# the save action extracts the contents of the entire database for the current environment # the save action extracts the contents of the entire database for the current environment
# and dumps it into the BackupFile#filename file # and dumps it into the BackupFile#filename file
def save def save
ApplicationDatabase.save_to_file(@file.path) ApplicationDatabase.zip_and_save_to_file(@file.path)
end end


def filename def filename
@file.path @file.path
end end


def filename_base def filename_base
File.basename(filename, ".sql") File.basename(filename, ".sql.gz")
end end


# extracts a time object from the filename of a backup file # extracts a time object from the filename of a backup file
Expand Down Expand Up @@ -99,7 +99,7 @@ def valid?
seconds = ("00".."60") seconds = ("00".."60")
date = "("+[years, months, days].map { |f| f.to_a.join("|") }.join(")-(") + ")" date = "("+[years, months, days].map { |f| f.to_a.join("|") }.join(")-(") + ")"
time = "("+[hours, minutes, seconds].map { |f| f.to_a.join("|") }.join(")-(") + ")" time = "("+[hours, minutes, seconds].map { |f| f.to_a.join("|") }.join(")-(") + ")"
reg = /^backups_#{date}_#{time}_(development|production)_dump.sql/ reg = /^backups_#{date}_#{time}_(development|production)_dump.sql.gz/
File.basename(filename_base+".sql")=~reg File.basename(filename_base+".sql.gz")=~reg
end end
end end

0 comments on commit 169332f

Please sign in to comment.