Reputation: 65
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
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
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"):
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
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
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
for more information see http://technet.microsoft.com/en-us/library/cc721846.aspx
Upvotes: 2