Permalink
Browse files

change controller to use compressed file format

  • Loading branch information...
1 parent 3d8d68c commit 169332f59867b090eef125adfb3bc702bc4aee7e @lazylester committed Mar 21, 2013
Showing with 7 additions and 7 deletions.
  1. +1 −1 app/controllers/get_back/backups_controller.rb
  2. +6 −6 app/models/backup_file.rb
@@ -59,7 +59,7 @@ def show
# overwrites the active database with the file passed in
def write_db(backfile)
if backfile.valid?
- ApplicationDatabase.restore_from_file(backfile) # returns false if restore fails
+ ApplicationDatabase.restore_from_zipfile(backfile) # returns false if restore fails
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."
false
View
@@ -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)
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
when :all
@@ -55,22 +55,22 @@ def destroy
def initialize(attributes={})
datestamp = "backups_"+Time.now.strftime("%Y-%m-%d_%H-%M-%S")
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])
end
# the save action extracts the contents of the entire database for the current environment
# and dumps it into the BackupFile#filename file
def save
- ApplicationDatabase.save_to_file(@file.path)
+ ApplicationDatabase.zip_and_save_to_file(@file.path)
end
def filename
@file.path
end
def filename_base
- File.basename(filename, ".sql")
+ File.basename(filename, ".sql.gz")
end
# extracts a time object from the filename of a backup file
@@ -99,7 +99,7 @@ def valid?
seconds = ("00".."60")
date = "("+[years, months, days].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/
- File.basename(filename_base+".sql")=~reg
+ reg = /^backups_#{date}_#{time}_(development|production)_dump.sql.gz/
+ File.basename(filename_base+".sql.gz")=~reg
end
end

0 comments on commit 169332f

Please sign in to comment.