Sha256: cf01cbb107f37f8dd4f1d604f7527a7ff62a2b7204634a2125c63a72ce14b154

Contents?: true

Size: 1.31 KB

Versions: 56

Compression:

Stored size: 1.31 KB

Contents

# encoding: utf-8

module Backup
  module Syncer
    module RSync
      class Pull < Push

        def perform!
          log!(:started)
          write_password_file!

          create_dest_path!
          run("#{ rsync_command } #{ host_options }#{ paths_to_pull } " +
              "'#{ dest_path }'")

          log!(:finished)
        ensure
          remove_password_file!
        end

        private

        ##
        # Returns the syntax for pulling multiple paths from the remote host.
        # e.g.
        #   rsync -a -e "ssh -p 22" host:'path1' :'path2' '/dest'
        #   rsync -a rsync_user@host::'modname/path1' ::'modname/path2' '/dest'
        #
        # Remove any preceeding '~/', since these paths are on the remote.
        # Also remove any trailing `/`, since we don't want rsync's
        # "trailing / on source directories" behavior.
        def paths_to_pull
          sep = mode == :ssh ? ':' : '::'
          directories.map {|dir|
            "#{ sep }'#{ dir.sub(/^~\//, '').sub(/\/$/, '') }'"
          }.join(' ').sub(/^#{ sep }/, '')
        end

        # Expand path, since this is local and shell-quoted.
        def dest_path
          @dest_path ||= File.expand_path(path)
        end

        def create_dest_path!
          FileUtils.mkdir_p dest_path
        end

      end
    end
  end
end

Version data entries

56 entries across 56 versions & 7 rubygems

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