Dec 15 2012

Windows Remote Server/NAS Backup Script

Published by at 3:35 pm under Backup




robocopy is provided with the Windows 2003 Server resource kit tools or natively in Windows 2008 Server.
Robocopy lets you copy but more interestingly synchronize data from a server (or a NAS) to another Windows server.
Synchronization takes little bandwidth and can be used to backup data over a slow network link.
 
Here’s a DOS script that synchronizes data from a remote server’s shared folders on to a local server. The local server can then be backed up with any usual backup software.
I use it for remote sites with files hosted on a NAS.
 

@echo off
CLS

SETLOCAL ENABLEDELAYEDEXPANSION
set REMOTE_NAS=192.168.1.250
set LOCAL_DIRECTORY=C:\Copy
set EXCLUDE_DIR="Shares Not To be Backed Up"

rem Go through server/NAS shares
for /F "tokens=1 delims=" %%K in ^
  ('net view %REMOTE_NAS%^|findstr Disk^|findstr /V %EXCLUDE_DIR%') do (
  set SHARELINE=%%K
  set SHARELINE=!SHARELINE:Disk=#!
  
  for /F "tokens=1 delims=#" %%S in ("!SHARELINE!") do (
    set SHARE=%%S
    echo Processing \\%REMOTE_NAS%\!SHARE!...
    robocopy "\\%REMOTE_NAS%\!SHARE!" "%LOCAL_DIRECTORY%\!SHARE!" ^
    /XF *.avi Thumbs.db /XD Temp* /E /COPY:DAT /R:0 /W:1 /NP
  )
)

 
Save with a BAT extension, modify settings according to your setup and create a scheduled task to be run every night.


No responses yet

Comments RSS

Leave a Reply