4th Dimension
4th Dimension

Reputation: 65

Scheduled task copying problems - no errors

I am building a script that will do database backup and will copy the backup to a safe storage location on another computer. I have that specific location already mounted on Y: and have built my script (.bat). The script runs fine in test runs, but when task scheduler runs it the part in charge of copying:

copy /Y "C:\something or other\Backup.bak" "Y:\DB\DB-%mydate%.bak"

doesn't run. In order to see what is going on when scheduler runs the script I appended

>> backup.log

to every line of the script. When I tried manually running the scrip through task scheduler in order to test what is the problem the only thing copy outputs is:

0 file(s) copied

and nothing else. No other error.

I know that Start Folder set in task could be the problem but I did set it to the folder where the script is. Also start folder shouldn't be an issue since all the time I'm working with full paths.

EDIT: I'm running this on Windows Server 2003 SP2 if it has anything to do with it.

So any ideas what could be the problem?

Upvotes: 0

Views: 4380

Answers (4)

George Clark
George Clark

Reputation: 41

I had the same problem. After more research and testing, I solved it via the following in my .bat file, using net use.

Helpful sites:
https://www.lifewire.com/net-use-command-2618096
https://lazyadmin.nl/it/net-use-delete/


First mount the shared folder.
net use z: \MyOtherServer\TheSharedFolder

Do the copy and specify the full path to the files.
copy D:\MyLocalFolder\active\File1.txt z:\TheDestinationFolder\active\

Delete the newly mounted drive.
/yes provides the confirmation answer to the prompt that comes up.
net use z: /delete /yes

Upvotes: 0

Adam Peterson
Adam Peterson

Reputation: 1

I was having this issue when trying to access/copy files from a protected network share via a Scheduled Task.

My problem was with the Scheduled Task's configuration. Using Win10, my Task was configured as follows (under "General" - "Security options"):

  • [ ] "Run only when user is logged on"
  • [x] "Run whether user is logged on or not"
    • [x] "Do not store password. The task will only have access to local resources" [This is the problem]

I fixed the problem by un-checking the "Do not store password" checkbox. Presumably, I could also fix it by opting for "Run only when user is logged on".

Upvotes: 0

Loïc MICHEL
Loïc MICHEL

Reputation: 26150

can you try to map the network drive inside the script or use UNC ? something like

pushd \\server\path
copy c:\backup.bak .
popd

Upvotes: 1

Alex Crichton
Alex Crichton

Reputation: 21

Hello I have recently done some work with Windows server Scheduled tasks.

The exit code may help you if you look at the task scheduler highlight your task and select the history tab 0x0 is success 0x1 is some kind of error but not very specific...

Some basic pointers

  • You can test the scheduled task by right clicking and selecting run
  • The user account the task is running as requires logon as batch user permissions on the server you intend to run the task on this can be added to local policy start> run/search gpedit.msc or by administering group policy on the domain.
  • If it is not the account you are using to test shift+right click command prompt and run as the user running the task then run your batch file this will at least give you confidence the user account can run the batch file interactively

for more information see http://technet.microsoft.com/en-us/library/cc721846.aspx

Upvotes: 2

Related Questions