我知道我可以这样:
rsync -zaP uploads/ myserver:/path/to/
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,那将压缩该目录中的每个文件并一一同步到服务器。但如果是数千个文件,则需要一些时间。压缩整个目录并上传要快得多。
那么,有没有一种瓷器方式可以让我做到这一点rsync?
我写了一个小 bash 函数来压缩和移动整个目录rsync。你会如何简化它或让它变得更好?
function zipsync() {
# Arguments
local source=$1
local target=$2
# Get the host and path from the $target string
IFS=':' read -a array <<< "$target"
local host=${array[0]}
local remote_path=${array[1]}
# The archive file locations
local remote_archive=${remote_path}${source}.tar.gz
local local_archive=${source}.tar.gz
# Colors
cya='\033[0;36m'; gre='\033[0;32m'; rcol='\033[0m'
echo -e "$cya Compressing files $rcol"
tar -zcvf $local_archive $source
echo -e "$cya Syncing files $rcol"
rsync -avP $local_archive $target
echo -e …Run Code Online (Sandbox Code Playgroud) rsync ×1