Backup – Windows Scheduled Task and WinRar

Posted: 2009-06-15 in Code and Computers
Tags:

A while back we needed to move about 2gb of daily generated logs from the running server to a backup locations. In order to keep things simple I went for a Winrar and Scheduled task combined solution. The alternative was to write a c# wrapper which is overkill or find a GUI application, also overkill.

The script is in red, comments are below…

REM @echo off
SET DESTRAR=\\ServerName\Share\Logs
SET SOURCEDIR=\\ServerName\baackups
SET RARPATH=C:\Program Files\WinRAR
REM Can also work with rar.exe
PATH=%PATH%;%RARPATH%
net use M: %SOURCEDIR% /persistent:no
if not exist M:\ goto _end
net use N: %DESTRAR% /persistent:no
if not exist N:\ goto _end
M:
winRAR.exe a -m3 -afzip -to2h -u -r -dw -agyymmdd N:\Logs_ *.*
c:
net use M: /DELETE
net use N: /DELETE
goto _end
:_end

How it works

winrar parts:

-r recursively backup
-u update
-m3 normal compression
-to2h only things 2 hours old (can be days also) This solves file lock issues
-afzip force to zip compression (NOT recommend as 2GB of files WILL break this, simply remove this flag to  leave as RAR files)
-dw Delete files just backed up  Note: WinRAR deletes the files AFTER the compression for fail safe reasons.
-agyymmdd n:\Logs_   The output file name Logs_date aka Logs_20091231

Now to get it working

  1. Install winrar
  2. Copy the code in red to a local file with a ‘.bat’ ending.
  3. Set the Dest and Source paths
  4. Setup your scheduled task (found under Accessories -> System Tools)

If you want download the command line and referance that instead, no installation nessasary (good for servers)

Cheers

Choco

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s