proxmox-utils/pct-push-r
Alex A. Naanou 551da5ded3 tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2023-12-30 18:05:58 +03:00

63 lines
1.2 KiB
Bash

#!/usr/bin/bash
#----------------------------------------------------------------------
#
#----------------------------------------------------------------------
case $1 in
-h|--help)
echo "Recursively push a directory to a CT creating the necessary paths"
echo
echo "Usage:"
echo " `basename $0` ID FROM TO"
echo
exit
;;
-*)
echo "Unknown option: $1"
exit
;;
esac
if [[ $# < 3 ]] ; then
echo ERR need both id and target id 1>&2
exit 1
fi
IFS=$'\n'
#----------------------------------------------------------------------
id=$1
from=$2
to=$3
# get from path relative to working directory...
if [[ ${from:0:1} != '/' ]] ; then
from="$(pwd)/${from}"
fi
#----------------------------------------------------------------------
dirs=($(find "$from" -type d))
for dir in "${dirs[@]}" ; do
if [[ "$dir" == "${to}" ]] ; then
continue
fi
dir=${dir#${from}}
lxc-attach $id -- mkdir -p "${to}/${dir}"
done
local files=($(find "$from" -type f))
for file in "${files[@]}" ; do
file=${file#${from}}
[ $QUIET ] \
|| echo "copy: \"${from}/${file}\" -> $id:\"${to}/${file}\""
pct push $id "${from}/${file}" "${to}/${file}"
done
#----------------------------------------------------------------------
# vim:set ts=4 sw=4 nowrap :