Raitis Veinbahs more about me my toy projects my github my asciinema

Customized rsync for vagrant

April 2, 2017

I needed more control over the paths that get transfered or even checked, since I was testing chef on EC2 from the home link(~0.5M down), but vagrant rsync’s only allows adding an exclude, which isn’t even regex, so I wrote my own.

I didn’t need to transfer non-chef paths or the cookbooks that I wasn’t changing at the moment. The script therefore lets you grep only the interesting (guest|host)dir pairs and add rsync’s --filter commands. (Took me a while to get those right.)

The paths are stored in .vagrant/machines/aws/aws/synced_folders and ARE NOT handled safely in this script, so review your input before you submit via CVR_RSYNC_COMMAND=echo.

% cat ~/work/scripts/chef-vagrant-rsync

dir_pairs() {
    jq -r < .vagrant/machines/aws/aws/synced_folders '.rsync | map("\(.hostpath) \(.guestpath)")[]'

usage() {
    echo "usage $1: <IP_ADDR> <SRC_GREP> <RSYNC_ARGS>*"

if [ "$#" -lt "2" ]; then
    usage "$(basename "$0")"

#dump-args "$@"
shift; shift

dir_pairs | grep -E "$src_grep" | while read src dst; do
    "${CVR_RSYNC_COMMAND:-rsync}" -r "$src" "ubuntu@$addr:$dst" "$@"

s|work/chef master % cat notes/cvr

~/work/scripts/chef-vagrant-rsync 'work/chef/(cookbooks|roles)' "$@" -vnr \
    --filter='+ **/cookbooks' \
    --filter='+ **/cookbooks/specific_cookbook**' \
    --filter='+ **/roles**' \