Skip to content

Instantly share code, notes, and snippets.

@iambryancs
Created June 5, 2023 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iambryancs/8521dfa859be939c91d3e21c42ed256d to your computer and use it in GitHub Desktop.
Save iambryancs/8521dfa859be939c91d3e21c42ed256d to your computer and use it in GitHub Desktop.
Kubernetes rsync wrapper
#!/bin/bash
# Source: https://serverfault.com/a/887402/169782
# Usage:
# krsync -av --progress --stats src-dir/ pod<@namespace>:/dest-dir
if [ -z "$KRSYNC_STARTED" ]; then
export KRSYNC_STARTED=true
exec rsync --blocking-io --rsh "$0" $@
fi
# Running as --rsh
namespace=''
pod=$1
shift
# If user uses pod@namespace, rsync passes args as: {us} -l pod namespace ...
if [ "X$pod" = "X-l" ]; then
pod=$1
shift
namespace="-n $1"
shift
fi
exec kubectl $namespace exec -i $pod -- "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment