epcim
10/20/2015 - 4:27 PM

msdos cmd cwrsync backup

msdos cmd cwrsync backup

@ECHO OFF
SETLOCAL

REM ********************************** EDIT THESE *************************************
REM Source drive letter where the folders you want to backup reside
SET SD=F

REM Name of source folders you want to backup
SET SFOLDER1=My Projects
SET SFOLDER2=Personal Backups

REM Destination drive letter where your backups will reside (e.g. a USB Hard Disk mounted as "G")
SET BD=G

REM Main backup folder whereinto your backups will be transferred
SET BFOLDER=CWRsync

REM Number of days you want to keep the stale copy of the items which were modified/deleted at source
SET DAY=90
REM ***** YOU MAY LEAVE THE REST INTACT IF YOU DON'T PLAN A FURTHER CUSTOMIZATION *****

REM Location of rsync and related files (e.g. C:\Program Files\cwRsync or C:\cwRsync etc.)
SET CWRSYNCHOME=%PROGRAMFILES%\cwRsync
SET CYGWIN=nontsec

REM Make cwRsync home as a part of system PATH to find required DLLs
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%;%PATH%

SET hour=%time:~0,2%
IF "%hour:~0,1%"==" " SET hour=0%time:~1,1%
SET BDATE=%date:~-4,4%%date:~-7,2%%date:~-10,2%
SET BTIME=hour_%hour%_%time:~3,2%

SET OPS=-ravb --itemize-changes --delete
SET BROOT=/cygdrive/%BD%/%BFOLDER%
SET BDIR=CHANGED

REM rsync process
rsync %OPS% --backup-dir=%BROOT%/%BDIR%/%BDATE%/%BTIME%/%SD%/"%SFOLDER1%" --exclude=%BROOT%/%BDIR% /cygdrive/%SD%/"%SFOLDER1%"/ %BROOT%/%SD%/"%SFOLDER1%"/
rsync %OPS% --backup-dir=%BROOT%/%BDIR%/%BDATE%/%BTIME%/%SD%/"%SFOLDER2%" --exclude=%BROOT%/%BDIR% /cygdrive/%SD%/"%SFOLDER2%"/ %BROOT%/%SD%/"%SFOLDER2%"/

REM deletion process
cd /D %BD%:\%BFOLDER%\%BDIR%
FOR /F "skip=%DAY% delims=" %%a IN ('DIR /B /AD 20?????? ^| SORT /R') DO RD /S /Q "%%a"