Using RoboCopy to copy my MSSQL backup

Today I was fiddling around with my MS SQL maintenance plan. I configured it to also make a copy of my database. Now I want some extra security and want to copy this file to a safe share within my network. This way if all my drives from my database server fail, I still have the file on my fileshare.

There are a massive amount of applications that you can for use for this. I used RoboCopy (which you can find in the Windows 2003 Resource kit), there is also a GUI version which you can use. But I just went for the good old console version.

Now I also wanted to log this action to a file, this way I can monitor these actions. But I don’t want a single file, I want a file for every day. In other words I want to use the current date and time in the filename of the log file. This of course requires some Bat programming action:

   1: @echo off
   2:  
   3: for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
   4: for /f "tokens=1" %%u in ('time /t') do set t=%%u
   5: if "%t:~1,1%"==":" set t=0%t%
   6: set timestr=%d:~6,4%%d:~0,2%%d:~3,2%_%t:~0,2%%t:~3,2%
   7:  

   8: "C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" /COPYALL 

      "F:\MSSQL\BACKUP" "\\ExternalServer\MSSQL BACKUP" > "F:\MSSQL\COPYLOG\%timestr%.txt"

No comments yet. Be the first.

Leave a reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word