Last active
July 18, 2018 15:52
-
-
Save ouyi/a1843a3963bc01589c36246acb6f4520 to your computer and use it in GitHub Desktop.
Server-to-server file copying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
set -euo pipefail | |
src_host="$1" | |
src_path="$2" | |
dst_host="$3" | |
dst_path="$4" | |
pattern="${5:-*}" | |
tmp_file="/var/tmp/test.data.tar.gz" | |
ssh -t $dst_host "sudo -s bash -c \"rm -f $tmp_file\"" | |
ssh -t $src_host "sudo -s bash -c \"rm -f $tmp_file\"" | |
ssh -t $src_host "sudo -s bash -c \"find '$src_path' -name '$pattern' -printf '%f\n' | tar czf $tmp_file -C $src_path --files-from=-\"" | |
scp -3 $src_host:$tmp_file $dst_host:$tmp_file | |
ssh -t $dst_host "sudo -s bash -c \"mkdir -p $dst_path && tar xzf $tmp_file -C $dst_path\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment