Sha256: b25a1ce48f14bbd7337ced83f2d11cd358c26e6b9b4a2b17f5eb742780e6c943

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Backs3
  class FileInfo
    include Backs3

    attr_reader :backup_info
    attr_reader :path
    attr_reader :md5sum

    def initialize(backup, path)
      @backup_info = backup
      @path = path
      @md5sum = md5(@path)
      @options = @backup_info.options
    end

    def storage
      @backup_info.storage
    end

    def ==(other_obj)
      other_obj.backup_info == self.backup_info && other_obj.path == self.path
    end

    def aws_filename
      File.join(@backup_info.key, path)
    end

    def backup
      logger.info "Backing up #{@path} to #{aws_filename}"
      storage.store(aws_filename, open(@path))
    end

    def restore(location = '/tmp')
      restore_path = File.join(location, @path)
      
      if storage.exists?(aws_filename)
        $stdout.write "Restoring file #{@path}"
        FileUtils.mkdir_p File.dirname(restore_path)
        File.open(restore_path, 'w') do |f|
          storage.read(aws_filename) do |segment|
            $stdout.write "."
            f.write segment
          end
        end
        $stdout.write "\n"
      else
        logger.info "Could not restore #{@path} because file data could not be found!"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
backs3-0.0.5 lib/backs3/file_info.rb