Class: BakFile
- Inherits:
-
SqliteActiveRecord
- Object
- ActiveRecord::Base
- SqliteActiveRecord
- BakFile
- Defined in:
- lib/bakfile.rb
Overview
Represents files that are either backed up, about to be backed up, or failed to be backed up.
Class Method Summary collapse
-
.delete_from_fs(delete_fid) ⇒ Bool
Delete from filesystem using just a fid.
-
.max_fid ⇒ Object
get the max fid that is backed up.
Instance Method Summary collapse
-
#bak_it ⇒ Bool
Get a file from MogileFS and save it to the destination path.
-
#restore ⇒ Bool
Restore a file back to a MogileFS domain.
Class Method Details
.delete_from_fs(delete_fid) ⇒ Bool
Delete from filesystem using just a fid
53 54 55 56 57 58 59 60 61 |
# File 'lib/bakfile.rb', line 53 def self.delete_from_fs(delete_fid) begin File.delete(PathHelper.path(delete_fid)) rescue Exception => e if $debug raise e end end end |
.max_fid ⇒ Object
get the max fid that is backed up
11 12 13 14 15 16 17 18 19 |
# File 'lib/bakfile.rb', line 11 def self.max_fid last_backed_file = BakFile.order("fid").last if last_backed_file max_fid = last_backed_file.fid else max_fid = 0 end max_fid end |
Instance Method Details
#bak_it ⇒ Bool
Get a file from MogileFS and save it to the destination path.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bakfile.rb', line 37 def bak_it begin path = PathHelper.path(self.fid) $mg.get_file_data(self.dkey, path) rescue Exception => e if $debug raise e end return false end true end |
#restore ⇒ Bool
Restore a file back to a MogileFS domain
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bakfile.rb', line 23 def restore path = PathHelper.path(self.fid) begin $mg.store_file(self.dkey, self.classname, path) rescue Exception => e if $debug raise e end end end |