[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Windows Task Scheduler donesn't run my backup script

Dear Experts,

I have a backup scrip that should backup data from local server to a shared drive.  the script shown under the code.  under Task Scheduler i set it to run at 10:00PM, even if user not logged on.  Under Task scheduler even it shows that task was run successfully but I don't see any backed up data?  if i double click the script it will run and make a copy of my data.

any ideas?

@echo off
set Source=E:\sourcedata
set Target=Z:\backup
set CopyCMD=xcopy /d /i /r /k /c /h /e /v /y
:: See XCOPY switches explained at:
:: support.microsoft.com/kb/289483
set Year=%date:~10,4%
set Month=%date:~7,2%
set Day=%date:~4,2%
mkdir %Target%\%Year%\%Month%\%Day%
%CopyCMD% %Source% %Target%\%Year%\%Month%\%Day%

Open in new window

3 Solutions
Krzysztof PytkoActive Directory EngineerCommented:
You said that task is run and completed undet Task Scheduler but nothing has happened. Please check if at least folders were created. For me it looks like task runs properly but insuficient rights to do the script.

Does scheduled task run on an account with appropriate credentials to read data from source directory and copy/overwrite it in target directory? Please ensure if that task is run on appropriate account.

Also you may want to save the output messages to a log file.

%CopyCMD% %Source% %Target%\%Year%\%Month%\%Day% >> logFile.txt

Now, you can verify the log file to check if it really executed without problems.
Gerwin Jansen, EE MVETopic Advisor Commented:
You should realize that a scheduled task that runs 'even if the user is not logged on' has no rights on the shared drive (Z) in your batch file. The other thing is that Z: does not even exist when the task is triggered. I'd suggest that you use a UNC path instead of Z: and configure the scheduled task with a username and password that has access to the UNC path that is being copied to.
uknet80Author Commented:
the solution was access to remove share drive:

this doesn't work
set Source=E:\sourcedata
set Target=Z:\backup

but this does
set Source=E:\sourcedata
set Target=\\server_IP_address\backup

thanks for your helps

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now