Class: EY::Backup::Database
- Inherits:
-
Object
- Object
- EY::Backup::Database
- Defined in:
- lib/ey_backup/database.rb
Instance Attribute Summary collapse
-
#backup_size ⇒ Object
readonly
Returns the value of attribute backup_size.
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#keep ⇒ Object
readonly
Returns the value of attribute keep.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #backups ⇒ Object
- #bucket_minder ⇒ Object
- #dump ⇒ Object
- #generate_basename ⇒ Object
-
#initialize(engine, base_path, keep, backend, environment, name) ⇒ Database
constructor
A new instance of Database.
- #number_to_human_size(size) ⇒ Object
- #start_upload(filenames) ⇒ Object
- #timestamp ⇒ Object
Constructor Details
#initialize(engine, base_path, keep, backend, environment, name) ⇒ Database
Returns a new instance of Database.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ey_backup/database.rb', line 4 def initialize(engine, base_path, keep, backend, environment, name) if name.nil? || name.empty? raise ArgumentError, "database name is blank" end @engine = engine @base_path = base_path @keep = keep @backend = backend @environment = environment @name = name @backup_size = nil end |
Instance Attribute Details
#backup_size ⇒ Object (readonly)
Returns the value of attribute backup_size.
16 17 18 |
# File 'lib/ey_backup/database.rb', line 16 def backup_size @backup_size end |
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
16 17 18 |
# File 'lib/ey_backup/database.rb', line 16 def base_path @base_path end |
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
16 17 18 |
# File 'lib/ey_backup/database.rb', line 16 def engine @engine end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
16 17 18 |
# File 'lib/ey_backup/database.rb', line 16 def environment @environment end |
#keep ⇒ Object (readonly)
Returns the value of attribute keep.
16 17 18 |
# File 'lib/ey_backup/database.rb', line 16 def keep @keep end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/ey_backup/database.rb', line 16 def name @name end |
Instance Method Details
#backups ⇒ Object
22 23 24 25 |
# File 'lib/ey_backup/database.rb', line 22 def backups s3_objects = bucket_minder.list("#{@environment}.#{@name}/").select { |o| o[:name] =~ @engine.suffix } s3_objects.map {|o| BackupSet.new(self, o[:name], nil, o[:keys]) }.sort end |
#bucket_minder ⇒ Object
18 19 20 |
# File 'lib/ey_backup/database.rb', line 18 def bucket_minder @backend.bucket_minder end |
#dump ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/ey_backup/database.rb', line 27 def dump FileUtils.mkdir_p(@base_path) basename = generate_basename file = @engine.dump(@name, basename) @backup_size = number_to_human_size(File.size(file)) BackupSet.from(self, basename, file) end |
#generate_basename ⇒ Object
41 42 43 |
# File 'lib/ey_backup/database.rb', line 41 def generate_basename File.join(@base_path, "#{@name}.#{}") end |
#number_to_human_size(size) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ey_backup/database.rb', line 49 def number_to_human_size(size) if size < 1024 "#{size} bytes" elsif size < 1024.0 * 1024.0 "%.01f KB" % (size / 1024.0) elsif size < 1024.0 * 1024.0 * 1024.0 "%.01f MB" % (size / 1024.0 / 1024.0) else "%.01f GB" % (size / 1024.0 / 1024.0 / 1024.0) end end |
#start_upload(filenames) ⇒ Object
37 38 39 |
# File 'lib/ey_backup/database.rb', line 37 def start_upload(filenames) @backend.start_upload(filenames, @environment, @name) end |
#timestamp ⇒ Object
45 46 47 |
# File 'lib/ey_backup/database.rb', line 45 def Time.now.strftime("%Y-%m-%dT%H-%M-%S") end |