Last active
October 26, 2022 09:51
-
-
Save sometimesfood/8b19f7156da4e8a2a1c385e8097a9a2b to your computer and use it in GitHub Desktop.
Windows rsync batch file
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
@ECHO OFF | |
SETLOCAL | |
SET ARGC=0 | |
FOR %%x IN (%*) DO SET /A ARGC+=1 | |
IF NOT %ARGC%==3 ( | |
ECHO Usage: %~n0 USER TARGET_HOST TARGET_DIR | |
GOTO :eof | |
) | |
SET BASEDIR=%~dp0 | |
SET PATH=%BASEDIR%\bin;%PATH% | |
SET TARGET_USER=%1 | |
SET TARGET_HOST=%2 | |
SET TARGET_DIR=%3 | |
SET SSH_DIR=%BASEDIR%\home\%USERNAME%\.ssh | |
SET SSH_KEY=%SSH_DIR%\id_ed25519 | |
IF NOT EXIST "%SSH_DIR%" GOTO SETUP_SSH | |
:RSYNC | |
rsync -rv --modify-window=1 --update --delete --progress -e "ssh -i '%SSH_KEY%'" -r --files-from include.txt --exclude-from exclude.txt /cygdrive/ %TARGET_USER%@%TARGET_HOST%:%TARGET_DIR% | |
ssh -i "%SSH_KEY%" %TARGET_USER%@%TARGET_HOST% touch "%TARGET_DIR%/.TIMESTAMP" | |
GOTO :eof | |
:SETUP_SSH | |
mkdir "%SSH_DIR%" | |
ssh-keygen -o -a 100 -t ed25519 -N "" -q -f "%SSH_KEY%" | |
type "%SSH_KEY%.pub" | ssh %TARGET_USER%@%TARGET_HOST% "mkdir -p .ssh && cat >> .ssh/authorized_keys" | |
GOTO RSYNC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment