Created
April 22, 2021 08:07
-
-
Save strizhechenko/e4b1807796b2d5bebb09964e0aad951d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
set -euE | |
echo "$0 $@ [$$] START" >&2 | |
if [ "${1:-}" == '--help' ]; then | |
echo "Info: $0 - утилита для синхронизации незакоммиченных изменений" | |
echo "Usage: [action=push|pull|once] $0 [CONFIG|<server> <directory> <interval>]" | |
echo "Example: $0 10.20.140.333 /home/xxx/git/yyy/ 300" | |
echo " отправлять на сервер изменения раз в пять минут" | |
exit 0 | |
fi | |
push() { | |
local server="$1" | |
local directory="$2" | |
ssh $server mkdir -p $directory 2>/dev/null | |
rsync -a -z --compress-level 9 --progress --delete "$directory" $server:$directory 2>/dev/null | |
return 0 | |
} | |
main() { | |
if [ -s "$1" ]; then | |
source "$1" | |
else | |
local server="$1" | |
local directory="$2" | |
fi | |
local timeout="${3:-${timeout:-60}}" | |
if [ "${action:-push}" = 'pull' ]; then | |
rsync -a --delete "$server:$directory" "$directory" | |
elif [ "${action:-push}" = 'once' ]; then | |
push "$server" "$directory" | |
else | |
while sleep "$timeout"; do | |
push "$server" "$directory" | |
echo "$(date) wait $timeout seconds" | |
done | |
fi | |
return 0 | |
} | |
main "$@" | |
echo "$0 $@ [$$] SUCCESS" >&2 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment