Jump to content
RESET Forums (homeservershow.com)
ikon

RoboCopy Backup Scripts

Recommended Posts

ikon

A few people have asked about the RoboCopy scripts I use to back up my data, so I thought I would put them into a thread of their own.

 

Here's the script I use to back up to my 2 sets of OffSite drives. It runs once a day in the middle of the night.

 

@echo on

 

If exist Q:\NUL.EXT goto Offsite-A

 

If exist R:\NUL.EXT goto Offsite-B

 

Echo Could not find drive Q: or R: for offsite backup > "<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

 

GoTo ExitDoor

 

REM=============================================================================================

 

:Offsite-A

 

Robocopy "<drive:>\ServerFolders" "Q:\ServerFolders" *.*  /e /r:2 /w:2 /tee /np /xd "<drive:>\serverfolders\Client Computer Backups" "<drive:>\serverfolders\backup\logs" "<drive:>\serverfolders\skydrive" /log+:"<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

 

Net stop "Windows Server Client Computer Backup Provider Service"

 

Robocopy "<drive:>\ServerFolders\Client Computer Backups" "Q:\ServerFolders\Client Computer Backups" *.*  /e /r:2 /w:2 /mir /tee /np /log+:"<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

Net start "Windows Server Client Computer Backup Provider Service"

 

GoTo ExitDoor

 

REM============================================================================================

 

:Offsite-B

 

Robocopy "<drive:>\ServerFolders" "R:\ServerFolders" *.*  /e /r:2 /w:2 /tee /np /xd "<drive:>\serverfolders\Client Computer Backups" "<drive:>\serverfolders\backup\logs" "<drive:>\serverfolders\skydrive" /log+:"<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

 

Net stop "Windows Server Client Computer Backup Provider Service"

 

Robocopy "<drive:>\ServerFolders\Client Computer Backups" "R:\ServerFolders\Client Computer Backups" *.*  /e /r:2 /w:2 /mir /tee /np /log+:"<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

 

Net start "Windows Server Client Computer Backup Provider Service"

 

GoTo ExitDoor

 

REM===========================================================================================

 

:ExitDoor

 

Ren "<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log" "BackupToOffsite_RoboCopy_%date%.log"

 

exit

 

The 'paragraphs' above are each a single line. The forum editor inserted the line breaks. Also, you may notice that section OffSite-A and OffSite-B are almost identical. That's deliberate. There are ways to reduce the amount of code by using variables, etc. but I prefer a more straightforward, less complicated approach. I'm a big believer in the KISS principle.

 

The 2 lines:

If exist Q:\NUL.EXT goto Offsite-A

If exist R:\NUL.EXT goto Offsite-B

are used to detect which set of OffSite drives is currently installed in the external enclosure. Each set of drives was given its own drive letter through Disk Manager when they were first set up.

 

Finally, you will need to replace the <drive:> entries with the drive letters that apply to your situation.

Share this post


Link to post
Share on other sites
ikon

Here's my NearLine backup RoboCopy script. It runs once a day, in the middle of the night.

 

@echo on

 

Robocopy "<drive:>\ServerFolders" "<drive:>\ServerFolders" *.* /e /r:1 /w:1 /tee /np /mir /xd "<drive:>\serverfolders\Client Computer Backups" "<drive:>\serverfolders\skydrive" /xf "<drive:>\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log" /log+:"<drive:>\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log"

 

Net stop "Windows Server Client Computer Backup Provider Service"

 

Robocopy "<drive:>\ServerFolders\Client Computer Backups" "<drive:>\ServerFolders\Client Computer Backups" *.* /e /r:1 /w:1 /mir /tee /np /log+:"<drive:>\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log"

 

Net start "Windows Server Client Computer Backup Provider Service"

 

exit

 

Each of the 'paragraphs' above is actually a single line. The wraparound is just the forum editor's formatting. I've also replaced the actual drive letters with a generic <drive:>. You have to replace it with the drive letters that apply in your situation.

Share this post


Link to post
Share on other sites
revengineer

Thanks for sharing the scripts!

Share this post


Link to post
Share on other sites
ikon

YW. Hopefully, some people will find them useful.

 

To tie it all together, here's a couple of links, one to my server setup and another to my backup strategy.

 

SERVER SETUP PHOTOS

 

http://homeservershow.com/forums/index.php?/topic/1899-whs-2011-storage-strategy/page__st__140#entry47628

 

BACKUP STRATEGY


http://homeservershow.com/forums/index.php?/topic/4788-what-i-hope-to-acheive-with-your-help/page__p__51373#entry51373

Share this post


Link to post
Share on other sites
seecott

Ikon,

 

Thank you for sharing the script.  I got a question.  Does your Backup Scripts support when files are in open status?  I previous wrote a script using RoboCopy but it always failed because the outlook pst file or other files are opened when the script run.

 

My example:

 

robocopy "C:\Users\Username" "U:\" /E /MIR /XJ /R:2 /W:10

 

 

Share this post


Link to post
Share on other sites
jem101

Generally speaking the answer is no. Robocopy can't do anything with a file locked open by another application, the /R and /W switches can help a bit by waiting and retrying a few times to see if the file gets released but be careful not to set them too high otherwise the entire job can take too long to complete.

 

As you have found .PST files are always an issue because Outlook locks them open in use. The only thing you can do is make sure that Outlook is closed before the job runs.

 

As far as I know, the only way of backing up an open file is via Windows Shadow Copy service.

 

 

John

Share this post


Link to post
Share on other sites
seecott

John, Thanks for confirming.  That's what I thought.  I'll take a look at Windows Shadow Copy.

Share this post


Link to post
Share on other sites
ikon

Yeah, as jem101 said, pretty much only Shadow Copy can copy open files. There are a few exceptions. For example, NotePad doesn't lock the files it has open, so they can be copied, but Outlook absolutely has to be closed for PST files to be copied.

Share this post


Link to post
Share on other sites
ikon

I've updated my scripts a little, mostly to consolidate things. Before, I had 2 scripts scheduled: one that backs up to my NearLine enclosure, and one that backs up to my OffSite enclosure. I've created a 3rd script that the other 2 one after the other, to ensure they don't stomp on each other.

Here's the new, 3rd script. I list it first because it's now the only one that's run by Task Scheduler. The other 2 scripts are dependent on this one:

 

call "BackupToNearLine_RoboCopy.cmd" %1
call "BackupToOffsite (AorB)_RoboCopy - Drive-B.cmd" %1

 

The "%1" at the end of the commands is so I can add "/tee" to the command that calls this script, so I can watch the process interactively if I want to run it manually for any reason.

 

Here is my current script to back up data to my NearLine enclosure:

 

@echo on

set tyme1=%time:~0,2%-%time:~3,2%-%time:~6,2%

Robocopy "<drive1>:\ServerFolders" "<drive2>:\ServerFolders" *.*  %1 /e /r:1 /w:1 /np /xd "<drive1>:\serverfolders\Client Computer Backups" "<drive1>:\serverfolders\skydrive" /xf "<drive1>:\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log" /log+:"<drive1>:\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log"

Net stop "Windows Server Client Computer Backup Provider Service"

Robocopy "<drive1>:\ServerFolders\Client Computer Backups" "<drive2>:\ServerFolders\Client Computer Backups" *.*  %1 /e /r:1 /w:1 /mir /np /log+:"<drive1>:\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log"

Net start "Windows Server Client Computer Backup Provider Service"

set tyme2=%time:~0,2%-%time:~3,2%-%time:~6,2%

Ren "<drive1>:\ServerFolders\Backup\logs\NearLine\BackupToNearLine_RoboCopy.log" "BackupToNearLine_RoboCopy_%date%_%tyme1%_%tyme2%.log"

exit

 

 

And here's my current script to back up data to my OffSite enclosure:

 

@echo on

set tyme1=%time:~0,2%-%time:~3,2%-%time:~6,2%

If exist <drive:>\NUL.EXT (
    set drive$=<drive3>
    goto Offsite-A
)

If exist <drive:>\NUL.EXT (
    set drive$=<drive4>
    goto Offsite-A
)

Echo Could not find drive <drive:> or <drive:> for offsite backup > "<drive:>\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

GoTo ExitDoor

REM==================================================================================================================================================

:Offsite-A

Robocopy "<drive1>:\ServerFolders" "%drive$%:\ServerFolders" *.*  %1 /e /r:2 /w:2 /np /xd "<drive1>:\serverfolders\Client Computer Backups" "<drive1>:\serverfolders\backup\logs" "<drive1>:\serverfolders\skydrive" /log+:"<drive1>:\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

REM pause

Net stop "Windows Server Client Computer Backup Provider Service"

Robocopy "<drive1>:\ServerFolders\Client Computer Backups" "%drive$%:\ServerFolders\Client Computer Backups" *.*  %1 /e /r:2 /w:2 /mir /np /log+:"<drive1>:\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log"

Net start "Windows Server Client Computer Backup Provider Service"


:ExitDoor

 

set tyme2=%time:~0,2%-%time:~3,2%-%time:~6,2%
Ren "<drive1>:\ServerFolders\Backup\logs\Offsite\BackupToOffsite_RoboCopy.log" "BackupToOffsite_RoboCopy_%date%_%tyme1%_%tyme2%.log"

exit

 

Be aware that the "tyme2" lines are dependent on the server's Short Date format being set to yyyy-MM-dd. Your server may or may not be set that way; most likely not. I chose this format for a few reasons, but one of them is so the log files will sort correctly by Name.

Share this post


Link to post
Share on other sites
jmwills

Near site error:

 

Robocopy "<drive:>\ServerFolders\Documents\amail"   

 

That should be email, right?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...