Sha256: 96572277e2d5d9ce4568401e4a85d0c3481a45163764d62a5eb7c6ff6c4f5f26

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

module Astrails
  module Safe
    class Local < Sink

      protected

      def active?
        # S3 can't upload from pipe. it needs to know file size, so we must pass through :local
        # will change once we add SSH/FTP sink
        true
      end

      def path
        @path ||= File.expand_path(expand(@config[:local, :path] || raise(RuntimeError, "missing :local/:path")))
      end

      def save
        puts "command: #{@backup.command}" if $_VERBOSE

        @backup.path = full_path # need to do it outside DRY_RUN so that it will be avialable for S3 DRY_RUN

        unless $DRY_RUN
          FileUtils.mkdir_p(path) unless File.directory?(path)
          benchmark = Benchmark.realtime do
            system "#{@backup.command}>#{@backup.path}"
          end
          puts("command took " + sprintf("%.2f", benchmark) + " second(s).") if $_VERBOSE
        end

      end

      def cleanup
        return unless keep = @config[:keep, :local]

        puts "listing files #{base}" if $_VERBOSE

        files = Dir["#{base}*"] .
          select{|f| File.file?(f) && File.size(f) > 0} .
          sort

        cleanup_with_limit(files, keep) do |f|
          puts "removing local file #{f}" if $DRY_RUN || $_VERBOSE
          File.unlink(f) unless $DRY_RUN
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
astrails-safe-0.2.3 lib/astrails/safe/local.rb
bostonlogic-safe-0.3.0 lib/astrails/safe/local.rb
astrails-safe-0.2.7 lib/astrails/safe/local.rb
astrails-safe-0.2.6 lib/astrails/safe/local.rb
astrails-safe-0.2.5 lib/astrails/safe/local.rb
astrails-safe-0.2.4 lib/astrails/safe/local.rb