3

So I'm trying to copy a backup of the data from my app. I wrote the batch script below to do this, but the script takes forever to run.

I start the batch script at 1am, and it is still running at 8:30am. This seems weird to me because when I copy the backup of my app manually in Windows File Explorer, it copies in 7-15 minutes depending on network traffic.

I REM the %backupcmd% "C:\Program Files\App\App Server\Data\Backups" "%drive%\" line. That was the original line of batch script I used to backup the data, and it worked efficiently up till a month ago.

So I tried the xcopy command with /d, so it would only copy source files that have been changed on or after that date (the current date), and the backups I'm copying are made at 12:01am every night and the copy backup script starts at 1am.

Any advice as to how to speed up my xcopy would be appreciated. If you think I should use powershell for this task too, I'm open to that option as well.

@echo off
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set yyyy=%ldt:~0,4%
set mm=%ldt:~4,2%
set dd=%ldt:~6,2%
:: variables
set drive=Z:\RootSoft\App\Data Backups
set backupcmd=xcopy /s /c /d /e /h /i /r /y /f /z
echo ### Backing up Backup...
REM %backupcmd% "C:\Program Files\App\App Server\Data\Backups" "%drive%\"
xcopy "C:\Program Files\App\App Server\Data\Backups" "Z:\RootSoft\App\Data Backups" /D:%mm%-%dd%-%yyyy% /s /c /e /h /i /r /y /f /z
:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."
echo Backup Complete!
echo %errorlevel%
pause
Paul
2,6982 gold badges20 silver badges28 bronze badges
asked Oct 1, 2015 at 13:52
2
  • Does your script actually finish if you wait long enough? Are you sure it's not hung with an error or waiting on user input? Commented Oct 1, 2015 at 14:15
  • I've had the script run for 24 hours until the next scheduled script run time starts, and it still doesn't finish. The script never asks for user input, and the /c makes xcopy ignore errors while copying. Commented Oct 1, 2015 at 14:45

2 Answers 2

7

You could try with ROBOCOPY and /MT switch which could accelerate the copy.

Also you can make some test by measuring the during process with TimeThis that can be found here (no need to be installed, just extract the exe with 7z in the current batch file folder)

answered Oct 1, 2015 at 14:02
Sign up to request clarification or add additional context in comments.

5 Comments

Cool, I'll see if that speeds up the copying
It made copying significantly faster!
Thanks. Experienced 3x speedup with ROBOCOPY vs XCOPY with ~2500 small files
'/MT:n' param has a argument 'n' to indicate the number of threads to be used, this number is between 1 and 128. ex: /MT:32
0
  • netsh interface tcp show global

  • netsh int tcp set heuristics disabled

  • netsh int tcp set global autotuninglevel=disabled
  • netsh int ip set global taskoffload=disabled

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.