Skip to content

Instantly share code, notes, and snippets.

@encoreshao
Created February 28, 2020 13:25
Show Gist options
  • Select an option

  • Save encoreshao/7b0a960ebb5d74c8eefda8ffd5a83382 to your computer and use it in GitHub Desktop.

Select an option

Save encoreshao/7b0a960ebb5d74c8eefda8ffd5a83382 to your computer and use it in GitHub Desktop.
[Ruby] - Download the config files from the server and upload it to another server
#!/usr/bin/env ruby
#
# Download the configuration file from the server and upload it to another server
#
# How to run it
#
# ruby sync-files.rb source_server target_server config_folder
require 'fileutils'
source_server = ARGV[0]
local_folder = "#{source_server}-configs"
target_server = ARGV[1]
dest_dir = ARGV[2]
FileUtils.mkdir_p local_folder
system("scp -r #{source_server}:#{dest_dir}/* #{local_folder}")
system("scp -r #{local_folder}/* #{target_server}:#{dest_dir}")
FileUtils.rm_r local_folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment