윈도우즈용 원격백업 rsync (cwRsync) 사용법

하늘 No.454 [컴퓨터] 3869
윈도우즈용 원격백업 rsync (cwRsync) 사용법 Photo-Image
윈도우즈용 원격백업 rsync (cwRsync) 사용법

cwRsync 프로그램 다운로드
https://www.itefix.net/cwrsync-client

압축을 풀어 bin 폴더내의 exe와 dll 파일만 적당한 곳에 복사합니다.

사용법 (아래 여러줄은 편의를 위한 것이며 실제는 한 줄로 입력, rsync 포트 접속 않고 ssh 로 바로 백업)
c:\CWRSYNC복사폴더\rsync.exe -avzr --stats --delete --ignore-errors
  -e "C:\CWRSYNC복사폴더\ssh.exe -p 722 -o StrictHostKeyChecking=no"
  --filter "merge C:\설정파일폴더\rsync_name_www_filter.txt"
  --log-file="C:\로그저장폴더\rsync_name_www_log.txt"
  "ID@서버주소:/백업할서버폴더/" "백업받을클라이언트폴더/"

-----------
rsync_server.name_backup.cmd

@echo off
SetLocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

rem Set Conole UTF-8 chcp 65001 : org chcp 949
chcp 65001

set PROGRAM_VER=heisme rsyncBackup v1.1a
TITLE=%PROGRAM_VER% - %~0

echo %PROGRAM_VER%
echo ============================

rem 서버의 백업 예정 폴더
set "SERVER_NAME=server.name"
set "SERVER_FOLDER=home/wwwFolder"
rem 백업 클라이언트에 저장될 폴더 SERVER_NAME_TARGET_DIR_SUB
set TARGET_DRIVE=U:
set TARGET_DIR=PUB\RsyncBackup
set TARGET_DIR_WIN=%TARGET_DRIVE%\%TARGET_DIR%
rem change U:\AA\BB to /cygdrive/U/AA/BB
set TARGET_DIR_CYG=/cygdrive/%TARGET_DRIVE::=%/%TARGET_DIR:\=/%
set TARGET_DIR_SUB=www

call :FUNC_CHECK_FOLDER "%TARGET_DIR_WIN%" Make
if %ERRORLEVEL% GEQ 10  (
  echo * Folder "%TARGET_DIR_WIN%" not exists. Terminate!
  goto :END_MSG
)

echo Change Drive and Folder %TARGET_DIR_WIN%
%TARGET_DRIVE%
cd "%TARGET_DIR_WIN%"

SET CWRSYNCHOME=RSYNC설치폴더
SET SSHHOME=%CWRSYNCHOME%
set BACKUP_USER=userid
set BACKUP_PASSWORD=

rem Print ssh version
echo.
echo Call rsync through SSH tunnel
"%SSHHOME%\ssh.exe" -V

echo.
rem --dry-run : Test 실행, 실제로 자료 변경, 기록은 없음
rem --partial : 중단시 전송중인 파일을 남겨둠, 사용안함
rem --update, -u skip files that are newer on the receiver 대상 파일(클라이언트) 변경(날짜가 이후)일 경우 서버파일을 받아오지 않는다, 사용안함
rem --delete : 서버파일 삭제시 백업클라이언트도 삭제
rem --ignore-errors : delete even if there are I/O errors
rem    --delete 옵션 사용시 서버 파일 삭제시 백업 클라이언트의 파일 삭제 안 되고 IO error encountered -- skipping file deletion 에러 날 때.
rem --progress  전송 속도 보임
rem ssh : rsync  client_loop: send disconnect: Connection reset by peer 에러시 아래 옵션 사용 검토
rem ssh -o TCPKeepAlive=yes -o ServerAliveCountMax=200
rem ssh -o TCPKeepAlive=no

rem set CMD_RSYNC=%CWRSYNCHOME%\rsync.exe -avzr --stats --delete --ignore-errors --progress
set CMD_RSYNC=%CWRSYNCHOME%\rsync.exe -avzr --stats --delete --ignore-errors
set CMD_RSYNC=%CMD_RSYNC% -e "%SSHHOME%\ssh.exe -p 722 -o StrictHostKeyChecking=no -o TCPKeepAlive=no"
rem 필터 (추가,제외파일 지정) 전체 백업이면 주석 rem 으로 막을 것
set CMD_RSYNC=%CMD_RSYNC% --filter "merge %SCRIPT_DIR%\rsync_%SERVER_NAME%_%TARGET_DIR_SUB%_filter.txt"
set CMD_RSYNC=%CMD_RSYNC% --log-file="%TARGET_DIR_WIN%\rsync_%SERVER_NAME%_%TARGET_DIR_SUB%-%DATE%_log.txt"
set CMD_RSYNC=%CMD_RSYNC% "%BACKUP_USER%@%SERVER_NAME%:/%SERVER_FOLDER%/" "%TARGET_DIR_CYG%/%SERVER_NAME%_%TARGET_DIR_SUB%/"
echo %CMD_RSYNC%
echo.

echo * Backup Received Folder : %CD%
echo * Backup Processing : %SERVER_NAME%/%SERVER_FOLDER%/ to %TARGET_DIR_WIN%\%SERVER_NAME%_%TARGET_DIR_SUB%\

echo.
CHOICE /T 15 /D N /M "Process Backup (백업을 진행 하시겠습니까?) (After 15s, Default No)"
IF not %ErrorLevel%x == 1x (
goto :END_MSG
)
echo File Backup is Processing
echo -------------------

echo.
echo * Password for server user %BACKUP_USER% / 서버 계정의 암호 입력
echo.
%CMD_RSYNC%

echo -------------------
echo * Backup Processed : %SERVER_NAME%/%SERVER_FOLDER%/ to %TARGET_DIR_WIN%\%SERVER_NAME%_%TARGET_DIR_SUB%\
goto END

rem ============================
:END_MSG
echo * Do Nothing. Process is Canceled (백업하지 않았습니다)

:END
timeout /T 15
EndLocal
echo ============================
exit /b 0
goto :EOF

rem Function ==================
:FUNC_CHECK_FOLDER
set "VERBOSE_LOCAL=True"
set "RETURN_VALUE=9"
set "FOLDERNAME_LOCAL=%~1%"
set "FOLDER_MAKE_FLAG_LOCAL=%~2%"

rem append \ if not end with
if not "%FOLDERNAME_LOCAL:~-1%"=="\" set "FOLDERNAME_LOCAL=%FOLDERNAME_LOCAL%\"

if exist "%FOLDERNAME_LOCAL%" (
set RETURN_VALUE=0
if "%VERBOSE_LOCAL%" == "True" (
echo Folder exists %FOLDERNAME_LOCAL%
)
) else (
set RETURN_VALUE=10
if "%VERBOSE_LOCAL%" == "True" (
echo -- Folder not exists %FOLDERNAME_LOCAL%
)

if "%FOLDER_MAKE_FLAG_LOCAL%" == "Make" (
set RETURN_VALUE=1
echo -- Make folder : %FOLDERNAME_LOCAL%
mkdir %FOLDERNAME_LOCAL%
)
)

rem Check
if not exist "%FOLDERNAME_LOCAL%" (
set RETURN_VALUE=10
echo Folder MAke Error %FOLDERNAME_LOCAL%
)

set VERBOSE_LOCAL=
exit /b %RETURN_VALUE%

rem ##############
rem  -(EOF)-


-----------
rsync_server.name_www_filter.txt

# Man page : rsync FILTER RULES
# --filter "merge filter_file.txt"
# https://stackoverflow.com/questions/35364075/using-rsync-filter-to-include-exclude-files
# https://www.nemonein.xyz/2021/06/5404/
# https://www.nemonein.xyz/2021/06/5356/
# 필터 디버깅 --debug=FILTER
# * : 모든 파일 , 단 / 는 아님 , 하위 전체 제외 - f/*
# ** : /를 포함한 모든 파일
# / : /** 과 동일
# *** : ** 보다 넓은 범위 , 하위 전체 추가 + f***
# 순서는 거꾸로 (아래에서 위로) 순차 적용, 가장 위에 것이 최후에 적용

###############
## 어느 경우도 삭제하지 말 것
#P *.html

#### 전체 #####
# gb Session file
- */data/session/sess_*
# 임시파일
- */tmp/*

###############
# 추가 및 삭제
## parentfolder 모두 포함, folder 전체 제외
# - parentfolder/folder*
# + parentfolder***
## parentfolder 모두 포함, folder 는 하위 폴더만 만듬 (파일 X)
# - parentfolder/folder/*/*
# + parentfolder***
## parentfolder 모두 제외, folder 만 포함
# + parentfolder/folder***
# - parentfolder/*

#### html2 #####
- html2/serverOther.name/cloud/app/cache/*
+ html2/serverOther.name/cloud/app***

# 폴더는 만들지만 파일 복사 안함
- html2/serverOther.name/cloud/*/*
+ html2/serverOther.name/cloud***

# 폴더 이하 전체 백업
+ html2/***

## 폴더 이하 전체 백업 제외
#- html2/*

#### html #####
# .확장자 있는 파일만 백업
+ html/server.name/imagelink/img-thumb/*.*
- html/server.name/imagelink/img-thumb/*

# 폴더 이하 전체 백업
+ html/***

# 기본 전체 백업

###############
# 용량 큰 파일 체크
# $ cd /home/www
# $ sudo du --max-depth=2 -h | sort -hr
###############
# -(EOF)-


-----------
옵션

--dry-run : 실행 연습, 실제 쓰는 것 없음
--partial : 중단시 전송중인 파일을 남겨둠,목록보기 약간 변함, 사용안함
--delete : 서버파일 삭제시 백업클라이언트도 삭제
--update, -u skip files that are newer on the receiver 대상 파일 변경시 덮어 쓰지 않음 : 꼭 사용 중요
--progress : 전송시 진행상황을 보여줍니다.

rsync -avzur --stats "아이디@서버주소:폴더/" "백업받을폴더/"

OPTION SUMMARY
Here is a short summary of the options available in rsync. Each option also has its own detailed description later in this manpage.

--verbose, -v increase verbosity
--info=FLAGS fine-grained informational verbosity
--debug=FLAGS fine-grained debug verbosity
--stderr=e|a|c change stderr output mode (default: errors)
--quiet, -q suppress non-error messages
--no-motd suppress daemon-mode MOTD
--checksum, -c skip based on checksum, not mod-time & size
--archive, -a archive mode is -rlptgoD (no -A,-X,-U,-N,-H)
--no-OPTION turn off an implied OPTION (e.g. --no-D)
--recursive, -r recurse into directories
--relative, -R use relative path names
--no-implied-dirs don’t send implied dirs with --relative
--backup, -b make backups (see --suffix & --backup-dir)
--backup-dir=DIR make backups into hierarchy based in DIR
--suffix=SUFFIX backup suffix (default ~ w/o --backup-dir)
--update, -u skip files that are newer on the receiver
--inplace update destination files in-place
--append append data onto shorter files
--append-verify --append w/old data in file checksum
--dirs, -d transfer directories without recursing
--old-dirs, --old-d works like --dirs when talking to old rsync
--mkpath create destination’s missing path components
--links, -l copy symlinks as symlinks
--copy-links, -L transform symlink into referent file/dir
--copy-unsafe-links only "unsafe" symlinks are transformed
--safe-links ignore symlinks that point outside the tree
--munge-links munge symlinks to make them safe & unusable
--copy-dirlinks, -k transform symlink to dir into referent dir
--keep-dirlinks, -K treat symlinked dir on receiver as dir
--hard-links, -H preserve hard links
--perms, -p preserve permissions
--executability, -E preserve executability
--chmod=CHMOD affect file and/or directory permissions
--acls, -A preserve ACLs (implies --perms)
--xattrs, -X preserve extended attributes
--owner, -o preserve owner (super-user only)
--group, -g preserve group
--devices preserve device files (super-user only)
--copy-devices copy device contents as a regular file
--write-devices write to devices as files (implies --inplace)
--specials preserve special files
-D same as --devices --specials
--times, -t preserve modification times
--atimes, -U preserve access (use) times
--open-noatime avoid changing the atime on opened files
--crtimes, -N preserve create times (newness)
--omit-dir-times, -O omit directories from --times
--omit-link-times, -J omit symlinks from --times
--super receiver attempts super-user activities
--fake-super store/recover privileged attrs using xattrs
--sparse, -S turn sequences of nulls into sparse blocks
--preallocate allocate dest files before writing them
--dry-run, -n perform a trial run with no changes made
--whole-file, -W copy files whole (w/o delta-xfer algorithm)
--checksum-choice=STR choose the checksum algorithm (aka --cc)
--one-file-system, -x don’t cross filesystem boundaries
--block-size=SIZE, -B force a fixed checksum block-size
--rsh=COMMAND, -e specify the remote shell to use
--rsync-path=PROGRAM specify the rsync to run on remote machine
--existing skip creating new files on receiver
--ignore-existing skip updating files that exist on receiver
--remove-source-files sender removes synchronized files (non-dir)
--del an alias for --delete-during
--delete delete extraneous files from dest dirs
--delete-before receiver deletes before xfer, not during
--delete-during receiver deletes during the transfer
--delete-delay find deletions during, delete after
--delete-after receiver deletes after transfer, not during
--delete-excluded also delete excluded files from dest dirs
--ignore-missing-args ignore missing source args without error
--delete-missing-args delete missing source args from destination
--ignore-errors delete even if there are I/O errors
--force force deletion of dirs even if not empty
--max-delete=NUM don’t delete more than NUM files
--max-size=SIZE don’t transfer any file larger than SIZE
--min-size=SIZE don’t transfer any file smaller than SIZE
--max-alloc=SIZE change a limit relating to memory alloc
--partial keep partially transferred files
--partial-dir=DIR put a partially transferred file into DIR
--delay-updates put all updated files into place at end
--prune-empty-dirs, -m prune empty directory chains from file-list
--numeric-ids don’t map uid/gid values by user/group name
--usermap=STRING custom username mapping
--groupmap=STRING custom groupname mapping
--chown=USER:GROUP simple username/groupname mapping
--timeout=SECONDS set I/O timeout in seconds
--contimeout=SECONDS set daemon connection timeout in seconds
--ignore-times, -I don’t skip files that match size and time
--size-only skip files that match in size
--modify-window=NUM, -@ set the accuracy for mod-time comparisons
--temp-dir=DIR, -T create temporary files in directory DIR
--fuzzy, -y find similar file for basis if no dest file
--compare-dest=DIR also compare destination files relative to DIR
--copy-dest=DIR ... and include copies of unchanged files
--link-dest=DIR hardlink to files in DIR when unchanged
--compress, -z compress file data during the transfer
--compress-choice=STR choose the compression algorithm (aka --zc)
--compress-level=NUM explicitly set compression level (aka --zl)
--skip-compress=LIST skip compressing files with suffix in LIST
--cvs-exclude, -C auto-ignore files in the same way CVS does
--filter=RULE, -f add a file-filtering RULE
-F same as --filter=’dir-merge /.rsync-filter’
repeated: --filter=’- .rsync-filter’
--exclude=PATTERN exclude files matching PATTERN
--exclude-from=FILE read exclude patterns from FILE
--include=PATTERN don’t exclude files matching PATTERN
--include-from=FILE read include patterns from FILE
--files-from=FILE read list of source-file names from FILE
--from0, -0 all *-from/filter files are delimited by 0s
--old-args disable the modern arg-protection idiom
--secluded-args, -s use the protocol to safely send the args
--trust-sender trust the remote sender’s file list
--copy-as=USER[:GROUP] specify user & optional group for the copy
--ignore-case ignore case when comparing filenames
--address=ADDRESS bind address for outgoing socket to daemon
--port=PORT specify double-colon alternate port number
--sockopts=OPTIONS specify custom TCP options
--blocking-io use blocking I/O for the remote shell
--outbuf=N|L|B set out buffering to None, Line, or Block
--stats give some file-transfer stats
--8-bit-output, -8 leave high-bit chars unescaped in output
--human-readable, -h output numbers in a human-readable format
--progress show progress during transfer
-P same as --partial --progress
--itemize-changes, -i output a change-summary for all updates
--remote-option=OPT, -M send OPTION to the remote side only
--out-format=FORMAT output updates using the specified FORMAT
--log-file=FILE log what we’re doing to the specified FILE
--log-file-format=FMT log updates using the specified FMT
--password-file=FILE read daemon-access password from FILE
--early-input=FILE use FILE for daemon’s early exec input
--list-only list the files instead of copying them
--bwlimit=RATE limit socket I/O bandwidth
--stop-after=MINS Stop rsync after MINS minutes have elapsed
--stop-at=y-m-dTh:m Stop rsync at the specified point in time
--fsync fsync every written file
--write-batch=FILE write a batched update to FILE
--only-write-batch=FILE like --write-batch but w/o updating dest
--read-batch=FILE read a batched update from FILE
--protocol=NUM force an older protocol version to be used
--iconv=CONVERT_SPEC request charset conversion of filenames
--tr=BAD/GOOD transliterate filenames
--checksum-seed=NUM set block/file checksum seed (advanced)
--ipv4, -4 prefer IPv4
--ipv6, -6 prefer IPv6
--version, -V print the version + other info and exit
--help, -h (*) show this help (* -h is help only on its own)

Rsync can also be run as a daemon, in which case the following options are accepted:

--daemon run as an rsync daemon
--address=ADDRESS bind to the specified address
--bwlimit=RATE limit socket I/O bandwidth
--config=FILE specify alternate rsyncd.conf file
--dparam=OVERRIDE, -M override global daemon config parameter
--no-detach do not detach from the parent
--port=PORT listen on alternate port number
--log-file=FILE override the "log file" setting
--log-file-format=FMT override the "log format" setting
--sockopts=OPTIONS specify custom TCP options
--verbose, -v increase verbosity
--ipv4, -4 prefer IPv4
--ipv6, -6 prefer IPv6
--help, -h show this help (when used with --daemon)




기타 윈도우즈용 동기화 프로그램
http://freealt.selfhow.com/cwrsync/

https://SkyMoon.info/a/HeismeNote/454  

가끔씩 그대 마음 흔들릴 때는 침묵으로 세월의 깊은 강을 건너가는 한 그루 나무를 보라 [이외수-가끔씩 그대 마음 흔들릴 때는]