Automation of setup and shedule backup jobs on Windows Server

Dec 16, 2013 at 3:12 PM
I used 7zbackup on many servers, but sometimes a feel lazy to setup it on new server..
i have small workaround for setting up sheduled backup tasks a bit faster..


i use 2 files:
start_bcp.cmd -starts powershell backup command
shedule.cmd -adds sheduled tasks

To setup sheduled task i only need two things:
  1. Set daily and weekly start time in top of shedule.cmd
  2. run shedule.cmd with command line arguments
Usage:
shedule.cmd [binpath] [inifilename] [destpath] [username] [password]

For example:
shedule.cmd "C:\BACKUP\Bin" v2.docs.ini "C:\BACKUP\Automatic\Docs" root password

This command will create 2 backup jobs, one for FULL backup every Sunday and one for Incremental backup every day except Sunday.

Here is code of those cmd files:
start_bcp.cmd
@ECHO OFF
set arctype=%1
set binpath=%2
set inifile=%3
set rotate=%4
set destpath=%5

if not defined arctype (
    ECHO arctype not defind!
    goto usage
)
if not defined binpath (
    ECHO binpath not defind!
    goto usage
)
if not defined inifile (
    ECHO inifile not defind!
    goto usage
)
if not defined rotate (
    ECHO rotate not defind!
    goto usage
)
if not defined destpath (
    ECHO destpath not defind!
    goto usage
)
goto run 
:USAGE
ECHO Use command line arguments: 
ECHO start_bcp.cmd [type] [inifilename] [rotate] [destpath]
ECHO Example:
ECHO start_bcp.cmd incr C:\BACKUP\BIN srv.doc.ini 10 C:\BCP\AUTO\DOC
goto exit

:RUN
ECHO Run variables:
ECHO arctype:  %arctype%
ECHO binpath:  %binpath%
ECHO inifile:  %inifile%
ECHO rotate:   %rotate%
ECHO destpath: %destpath
ECHO Starting %arctype% backup for %inifile%...
powershell %binpath%\7zBackup.ps1 --type %arctype% --selection %binpath%\%inifile% --rotate %rotate% --logfile %binpath%\log\%inifile%.%type%.log --destpath %destpath% 

:EXIT
shedule.cmd
@ECHO OFF

REM ================== SETUP ==================
set dailystarttime=04:00
set weeklystarttime=04:30
REM ===========================================


set binpath=%1
set inifile=%2
set destpath=%3
set user=%4
set pass=%5

if not defined binpath (
    ECHO binpath not defind!
    goto usage
)
if not defined inifile (
    ECHO inifile not defind!
    goto usage
)
if not defined destpath (
    ECHO destpath not defind!
    goto usage
)
if not defined user (
    ECHO user not defind!
    goto usage
)
if not defined pass (
    ECHO password not defind!
    goto usage
)

goto run 

:USAGE
ECHO Use command line arguments: 
ECHO shedule.cmd [binpath] [inifilename] [destpath] [username] [password]
ECHO Example:
ECHO shedule.cmd C:\BACKUP\BIN srv.doc.ini C:\BCP\AUTO\DOC root password
goto exit

:RUN
ECHO Run variables:
ECHO binpath:  %binpath%
ECHO inifile:  %inifile%
ECHO destpath: %destpath%
ECHO user: %user%
ECHO password: %pass%
set prefix=DOCS

REM =============== DAILY INCREMENTAL START ==============
set period=WEEKLY
set days="MON, TUE, WED, THU, FRI, SAT"
set runcmd="%binpath%\start_bcp.cmd incr %binpath% %inifile% 10 %destpath%"
ECHO Adding task for INCREMENTAL DAILY start of %inifile% configuration..
schtasks.exe /create /tn "7Z Backup %inifile% INCR Daily" /TR %runcmd% /sc %period% /D %days% /ST %dailystarttime% /RU %user% /RP %pass% /IT /RL HIGHEST /F

REM =============== WEEKLY FULL START ===================
set period=WEEKLY
set days="SUN"
set runcmd="%binpath%\start_bcp.cmd full %binpath% %inifile% 4 %destpath%"
ECHO Adding task for FULL Weekly start of %inifile% configuration..
schtasks.exe /create /tn "7Z Backup %inifile% FULL Weekly" /TR %runcmd% /sc %period% /D %days% /ST %weeklystarttime% /RU %user% /RP %pass% /IT /RL HIGHEST /F

:EXIT
Coordinator
Dec 16, 2013 at 4:59 PM
Nice. Thank you.