Looking for a Rotation Bat Script

5 posts / 0 new
Last post
danlee
Offline
Last seen: 8 years 11 months ago
Joined: 26.04.2012 - 03:10
Looking for a Rotation Bat Script

So I now have RSync working properly :D

 

So I would like to keep 7 days of backup and up to 52 weekly backups.  Does  anyone have  a bat script that already does this or something similar ?

danlee
Offline
Last seen: 8 years 11 months ago
Joined: 26.04.2012 - 03:10
I have not had a chance to

I have not had a chance to try it out, but this is what I have come up with, suggestions ?  I would like to add a check to make sure the folder exists before running the commands.

 

@ECHO OFF

 

REM Make environment variable changes local to this batch file

 

SETLOCAL

 

REM where to find rsync and related files

 

SET CWRSYNCHOME=C:\Program Files (x86)\cwRsync

 

REM Set HOME variable to your appdata directory. That makes sure that

 

REM ssh command creates known_hosts in a directory you have access.

 

SET HOME=C:\Users\Administrator.SERVER\AppData\Roaming

 

REM Make cwRsync home as a part of system PATH to find required DLLs

 

SET CWOLDPATH=%PATH%

 

SET PATH=%CWRSYNCHOME%\BIN;%PATH%

 

for /f %%a in ('date /t') do set DAY=%%a

if %DAY%==Mon goto :skipprocessing

if %DAY%==Tue goto :skipprocessing

if %DAY%==Wed goto :skipprocessing

if %DAY%==Thu goto :skipprocessing

if %DAY%==Fri goto :skipprocessing

if %DAY%==Sat goto :skipprocessing

 

:: put your processing here

"C:\Program Files\7-Zip\7z.exe" a -t7z "E:\rotate\weekly\backup-%date:~-4,4%-%date:~-10,2%-%date:~-7,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%.7z" "E:\rotate\day\7\backup"

 

:skipprocessing

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt -e "/cygdrive/E/rotate/day/6/backup" "/cygdrive/E/rotate/day/7"

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt -e "/cygdrive/E/rotate/day/5/backup" "/cygdrive/E/rotate/day/6"

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt -e "/cygdrive/E/rotate/day/4/backup" "/cygdrive/E/rotate/day/5"

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt -e "/cygdrive/E/rotate/day/3/backup" "/cygdrive/E/rotate/day/4"

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt -e "/cygdrive/E/rotate/day/2/backup" "/cygdrive/E/rotate/day/3"

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt -e "/cygdrive/E/rotate/day/1/backup" "/cygdrive/E/rotate/day/2"

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt  -e "'C:\Program Files (x86)\cwRsync\bin\ssh.exe' -v -i /cygdrive/C/temp" "xxxxxx@xxxxxx:/backup" "/cygdrive/E/rotate/day/1"

danlee
Offline
Last seen: 8 years 11 months ago
Joined: 26.04.2012 - 03:10
Here is my final script :) 

Here is my final script :)  Rotates daily, and compreses weekly :D

 

@ECHO OFF
SETLOCAL
SET CWRSYNCHOME=C:\Program Files (x86)\cwRsync
SET HOME=C:\home\root
SET CWOLDPATH=%PATH%
SET PATH=%CWRSYNCHOME%\BIN;%PATH%

for /f %%a in ('date /t') do set DAY=%%a

if %DAY%==Mon goto :skipweekly
if %DAY%==Tue goto :skipweekly
if %DAY%==Wed goto :skipweekly
if %DAY%==Thu goto :skipweekly
if %DAY%==Fri goto :skipweekly
if %DAY%==Sat goto :skipweekly

if NOT EXIST "E:\rotate\day\7\backup" goto :skipweekly

"C:\Program Files\7-Zip\7z.exe" a -t7z "E:\rotate\weekly\backup-%date:~-4,4%-%date:~-10,2%-%date:~-7,2%_%time:~0,2%-%time:~3,2%-%time:~6,2%.7z" "E:\rotate\day\7\backup"

:skipweekly

if NOT EXIST "E:\rotate\day\6\backup" goto :skipday7

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt "/cygdrive/E/rotate/day/6/backup" "/cygdrive/E/rotate/day/7"

:skipday7

if NOT EXIST "E:\rotate\day\5\backup" goto :skipday6

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt "/cygdrive/E/rotate/day/5/backup" "/cygdrive/E/rotate/day/6"

:skipday6

if NOT EXIST "E:\rotate\day\4\backup" goto :skipday5

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt "/cygdrive/E/rotate/day/4/backup" "/cygdrive/E/rotate/day/5"

:skipday5

if NOT EXIST "E:\rotate\day\3\backup" goto :skipday4

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt "/cygdrive/E/rotate/day/3/backup" "/cygdrive/E/rotate/day/4"

:skipday4

if NOT EXIST "E:\rotate\day\2\backup" goto :skipday3

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt "/cygdrive/E/rotate/day/2/backup" "/cygdrive/E/rotate/day/3"

:skipday3

if NOT EXIST "E:\rotate\day\1\backup" goto :skipday2

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt "/cygdrive/E/rotate/day/1/backup" "/cygdrive/E/rotate/day/2"

:skipday2

"C:\Program Files (x86)\cwRsync\bin\rsync.exe" --delete -rlt  -e "'C:\Program Files (x86)\cwRsync\bin\ssh.exe'" "xxx@xxxxxx:/backup" "/cygdrive/E/rotate/day/1"

 

itefix
Offline
Last seen: 11 hours 36 min ago
Joined: 01.05.2008 - 21:33
You may also have a look at
itefix
Offline
Last seen: 11 hours 36 min ago
Joined: 01.05.2008 - 21:33
Check also logwot8 -

Check also logwot8 - Logrotate for Windows. It may help to organize your log rotation requirements.