title: Batch file to backup data to networked drive?
body: <p>I am trying to create a backup of some local files on one machine, to a networked hard drive on another machine. The source computer is running Windows Server 2008 R2, and the destination machine is running Windows Server 2003 R2. I want to create a batch file that will run on the source computer, and copy all of the files in the D:\MICROS folder to a separate network drive. \marketing\TeraByte\marketingdata\MICROS\TESTBKUP\ is where the files will need to end up. The batch file will be executed through the task scheduler, and should run regardless of whether or not a user is logged in. I tried to make the batch file myself, and this was the best I could come up with </p>
  
  <pre><code>rem 05.21.2014 - script to Backup the 1 TB drive attached to marketing server.
  rem - use program to determine day of wek - then use the DAY of THE WEEK as the sub dir name
  set y =%date:~-4,4%
  set m =%date:~-10,2%
  set d =%date:~-7,2%
  set today = %y%%m%%d%
  set DOW=%1
  echo on
  echo DOW
  net use M: /D
  net use M: \\marketing\TeraByte\marketingdata\
  xCopy D:\MICROS\*.*       M:\MICROS\TESTBKUP\            /CDEFHIY &gt; M:\MICROS\BU%today%MICROS%DOW%.TXT
  echo Yes, the task really did execute &gt;&gt; \\marketing\TeraByte\MarketingData\MICROS\TESTBKUP\testlog.txt\
  pause
  :end
  </code></pre>
  
  <p>The stuff at the beginning is just used to generate a date, and that was all copy/pasted from a script my boss had already created. Where my code starts is after the "echo DOW" line. Whenever I try to get this to run, the task scheduler returns an operational code 2, and says the operation successfully completed, but none of the files were actually copied.</p>
  
  <p>What really confuses me about this whole thing, is that even though this script doesn't work, despite mapping the drive and using UNC paths, is that the following script created by my boss never mentions any network locations, yet it runs flawlessly and backs up the files to exactly the correct network drive. The Z: drive isn't even mapped on the server that script runs on, and yet it somehow knows it needs to go over the network.:</p>
  
  <pre><code>rem
  rem 04.09.2010 - script to Backup to 4 Terabyte drive attached to Stephs new windows 7 64bit PC
  rem - use program to determine day of week - then use the DAY of THE WEEK as the sub dir name
  REM 5.25.10 add RevAcctg and exclusion directories
  set y=%date:~-4,4%
  set m=%date:~-10,2%
  set d=%date:~-7,2%
  set today=%y%%m%%d%
  set DOW=%1
  echo on
  echo dow
  xCopy  \\MArketing2\AlysonAvino\*.*     Z:\backup\AlysonAvini\%DOW%\        /CDEFHIY &gt;  Z:\BU%today%Alyson%DOW%.TXT
  rem goto end
  xCopy  D:\DiskImage\*.*        V:\backup\DiskImage\               /CDEFHIY &gt;  V:\BU%today%DiskImage%DOW%.TXT
  xCopy  D:\MarkWolf\*.*         Z:\backup\MarkWolf\%DOW%\          /CDEFHIY &gt;  Z:\BU%today%MarkWolf%DOW%.TXT
  xcopy  \\otbdata\greatPlains\Bill  Z:\Backup\Bill\%DOW%\          /CDEFHIY &gt;  Z:\BU%today%Bill%DOW%.txt
  xcopy  \\otbdata\greatPlains\MSDynamicsGP\FrxServer  Z:\Backup\FrxServer\%DOW%\            /CDEFHIY &gt;  Z:\BU%today%FrxServer%DOW%.txt
  xcopy  \\otbdata\greatPlains\CrystalReports  Z:\Backup\CrystalReports\BU%today%\  /CDEFHIY &gt;  Z:\BU%today%Crystal%DOW%.txt
  xcopy  \\otbdata\greatPlains\RevAcctG  Z:\Backup\RevAcctG\BU%today%\  /CDEFHIY &gt;  Z:\BU%today%RevAcctG%DOW%.txt
  xcopy  D:\administration\*.*  Z:\BACKUP\ADMINISTRATION\%DOW%\     /CDEFHIY &gt;  Z:\BU%today%ADMIN%DOW%.TXT
  xcopy  D:\accounting\*.*      Z:\backup\ACCOUNTING\%DOW%\         /CDEFHIY &gt;  Z:\BU%today%ACCT%DOW%.TXT
  xCopy  D:\HR\*.*              Z:\backup\HR\%DOW%\                 /CDEFHIY &gt;  Z:\BU%today%HR%DOW%.TXT
  xcopy  F:\marketingdata\*.*   Z:\backup\MARKETING\%DOW%\          /CDEFHIY &gt;  Z:\BU%today%MRKT%DOW%.TXT
  xcopy  D:\surveillance\*.*    Z:\backup\Surveillence\%DOW%\       /CDEFHIY &gt;  Z:\BU%today%Surv%DOW%.TXT
  xCopy  D:\CD\*.*              Z:\backup\CD\%DOW%\                 /CDEFHIY &gt;  Z:\BU%today%CD.TXT
  xCopy  C:\Maintenance\*.*     Z:\backup\Maint\%DOW%\              /CDEFHIY &gt;  Z:\BU%today%Maint%DOW%.TXT
  xCopy  D:\Schedule\*.*        Z:\backup\Schedule\%DOW%\           /CDEFHIY &gt;  Z:\BU%today%Schedule%DOW%.TXT
  xCopy  D:\printshop\*.*       Z:\backup\printshop\%DOW%\          /CDEFHIY &gt;  Z:\BU%today%printshop%DOW%.TXT
  xCopy  F:\Exclusion\*.*       Z:\backup\Exclusion\%DOW%\          /CDEFHIY &gt;  Z:\BU%today%Exclusion%DOW%.TXT
  xCopy  F:\GAMING\*.*          Z:\backup\GAMING\%DOW%\             /CDEFHIY &gt;  Z:\BU%today%GAMING%DOW%.TXT
  xCopy  F:\LUBA\*.*            Z:\backup\SrvrLUBA\%DOW%\           /CDEFHIY &gt;  Z:\BU%today%SrvrLuba%DOW%.TXT
  xCopy  F:\AdamSecured\*.*     Z:\backup\AdamSecured\%DOW%\        /CDEFHIY &gt;  Z:\BU%today%AdamSecured%DOW%.TXT
  xCopy  D:\DOWNLOADS\*.*       Z:\backup\DOWNLOADS\%DOW%\          /CDEFHIY &gt;  Z:\BU%today%DOWNLOADS%DOW%.TXT
  xCopy  F:\MartyFiles\*.*      Z:\backup\MartyFiles\%DOW%\         /CDEFHIY &gt;  Z:\BU%today%MartyFiles%DOW%.TXT
  xCopy  F:\LUBAold\*.*         Z:\backup\LUBAold\%DOW%\            /CDEFHIY &gt;  Z:\BU%today%LUBAold%DOW%.TXT
  xCopy  D:\TestSecurity\*.*    Z:\backup\TestSecurity\%DOW%\       /CDEFHIY &gt;  Z:\BU%today%TestSecurity%DOW%.TXT
  :end
  rem do this on mkt2 server XCOPY  G:\*.*    Z:\BACKUP\CreativeGraphics\%DOW%\   /CDEFHIY   &gt; Z:\BU%Today%CreativeGraphics%DOW%.TXT
  </code></pre>
  
  <p>I've been working on this for days and have had no success. I've tried every possible fix I could think of, and trawled the internet for answers, but to no avail.</p>