Class: KuberKit::Shell::Commands::RsyncCommands

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/shell/commands/rsync_commands.rb

Instance Method Summary collapse

Instance Method Details

#rsync(shell, source_path, target_path, target_host: nil, exclude: nil, delete: true) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kuber_kit/shell/commands/rsync_commands.rb', line 2

def rsync(shell, source_path, target_path, target_host: nil, exclude: nil, delete: true)
  # Add a trailing slash to directory to have behavior similar to CP command
  if path_is_directory?(source_path) && !source_path.end_with?("/")
    source_path = "#{source_path}/"
  end

  if target_host
    destination = "#{target_host}:#{target_path}"
  else
    destination = target_path
  end

  args = [source_path, destination]
  if exclude
    Array(exclude).each do |e|
      args << "--exclude=#{e}"
    end
  end

  if delete
    args << "--delete"
  end

  shell.exec!(%Q{rsync -a #{args.join(' ')}}, merge_stderr: true)
end