Sha256: 7731cba0d878df014a15b1a62fbc3d4d9c90cc44289d167c88a06d1a1b89d03f

Contents?: true

Size: 1.71 KB

Versions: 56

Compression:

Stored size: 1.71 KB

Contents

# encoding: utf-8

module Backup
  module Storage
    class Local < Base
      include Storage::Cycler
      class Error < Backup::Error; end

      def initialize(model, storage_id = nil)
        super

        @path ||= '~/backups'
      end

      private

      def transfer!
        FileUtils.mkdir_p(remote_path)

        transfer_method = package_movable? ? :mv : :cp
        package.filenames.each do |filename|
          src = File.join(Config.tmp_path, filename)
          dest = File.join(remote_path, filename)
          Logger.info "Storing '#{ dest }'..."

          FileUtils.send(transfer_method, src, dest)
        end
      end

      # Called by the Cycler.
      # Any error raised will be logged as a warning.
      def remove!(package)
        Logger.info "Removing backup package dated #{ package.time }..."

        FileUtils.rm_r(remote_path_for(package))
      end

      # expanded since this is a local path
      def remote_path(pkg = package)
        File.expand_path(super)
      end
      alias :remote_path_for :remote_path

      ##
      # If this Local Storage is not the last Storage for the Model,
      # force the transfer to use a *copy* operation and issue a warning.
      def package_movable?
        if self == model.storages.last
          true
        else
          Logger.warn Error.new(<<-EOS)
            Local File Copy Warning!
            The final backup file(s) for '#{ model.label }' (#{ model.trigger })
            will be *copied* to '#{ remote_path }'
            To avoid this, when using more than one Storage, the 'Local' Storage
            should be added *last* so the files may be *moved* to their destination.
          EOS
          false
        end
      end

    end
  end
end

Version data entries

56 entries across 56 versions & 7 rubygems

Version Path
backup-ssh-4.4.5 lib/backup/storage/local.rb
backup-remote-0.0.19 lib/backup/storage/local.rb
cm-backup-1.0.0 lib/backup/storage/local.rb
backup-ssh-4.4.4 lib/backup/storage/local.rb
backup-ssh-4.4.3 lib/backup/storage/local.rb
backup-4.4.1 lib/backup/storage/local.rb
backup-remote-0.0.18 lib/backup/storage/local.rb
backup-remote-0.0.17 lib/backup/storage/local.rb
backup-remote-0.0.16 lib/backup/storage/local.rb
backup-remote-0.0.15 lib/backup/storage/local.rb
backup-ssh-4.4.2 lib/backup/storage/local.rb
backup-ssh-4.4.1 lib/backup/storage/local.rb
backup-remote-0.0.14 lib/backup/storage/local.rb
backup-remote-0.0.13 lib/backup/storage/local.rb
backup-remote-0.0.12 lib/backup/storage/local.rb
backup-remote-0.0.11 lib/backup/storage/local.rb
backup-ssh-4.4.0 lib/backup/storage/local.rb
backup-remote-0.0.10 lib/backup/storage/local.rb
backup-remote-0.0.9 lib/backup/storage/local.rb
backup-remote-0.0.8 lib/backup/storage/local.rb