Link to home
Start Free TrialLog in
Avatar of SW111
SW111

asked on

How to copy and rename folder using task scheduler in windows 2003 server

I would like to schedule to copy a folder from one server to another server.
I imagine that this can be done easily with task scheduler.

My difficulty is that I need to rename the folder we are trying to copy.
For example:
Source - Server A - Folder "Backup"
Destination - Server B - Folder "Backup18Dec2013"

So basically I would like to rename the folder being copied to include the date it is being copied.

We are using WIndows 2003

Thank you in advance.
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

The command you need here is xcopy
http://pcsupport.about.com/od/commandlinereference/p/xcopy-command.htm

eg

Xcopy /S /I /E /H D:\data\documents E:\Newfolder\documents
http://www.windows-commandline.com/xcopy-command-syntax-examples/

Michael
You can use %date% to get the current date value

This link shows how to format the date to a suitable format

http://www.computerhope.com/issues/ch000987.htm

Michael
Avatar of SW111
SW111

ASKER

Thanks Michael,
but I havent figure out how to use the two command in task scheduler.

Should I run them separately:
1. tun xcopy in server A, to copy to server B
2. schedule rename in server B

or (preferably) can I run them in one go like:
1. in server A:
Xcopy /S /I /E /H D:\Backup \\Server2\ScheduledBackup\Backup%date%

Thanks
Avatar of SW111

ASKER

So I've tried this and get a failed result:

Xcopy /S /I /E /H F:\Backup\testcopy\ \\DATASERVER03\Secondary Backup\testcopy-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,
2%m%time:~6,2%s%\

Invalid number of parameters

where F:\Backup\testcopy\ is the directory I'm trying to copy

and \\DATASERVER03\Secondary Backup\ is the location inside which I would like to put the copy of source directory

and the rest, I basically copy and paste because I have no idea what they mean.

Thanks
The error is cause by spaces in the path. You need to enclose the path in double quotes to resolve this


Xcopy /S /I /E /H "F:\Backup\testcopy\" "\\DATASERVER03\Secondary Backup\testcopy-"%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,
2%m%time:~6,2%s%\

Michael
Avatar of SW111

ASKER

Hi Michael, still have a bit of glitch:

C:\Users\myuser>Xcopy /S /I /E /H "F:\FMP Backup\test.txt.txt" "\\DATASERVER03\FMP Secondary Backup\testcopy-"%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%t
ime:~3,2%m%time:~6,2%s%.txt
Does \\DATASERVER03\FMP Secondary Backup\testcopy-12-20-2013_@_12h22m21s%.txt sp
ecify a file name
or directory name on the target
(F = file, D = directory)? f
F:\FMP Backup\test.txt.txt
1 File(s) copied

2. BUT when I do it for a folder:

C:\Users\myuser>Xcopy /S /I /E /H "F:\FMP Backup\test\" "\\DATASERVER03\FMP Seconda
ry Backup\test-"%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,2%m%
time:~6,2%s%\
Invalid path
0 File(s) copied

So my questions are:
a. how to make it work for folders
b. how to auto choose file/directory in case 1? (I will use this with task scheduler)

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SW111

ASKER

Michael,

That was AWESOME.
Thank you very much.

I dont understand 85% of the command, but it works like a charm.

Wish you a Happy New Year!
Avatar of SW111

ASKER

Uh, Michael, actually, can you help me with one more question?

How do I input this into Task scheduler in windows 2008 server?
I tried it but the argument box is not long enough to fit all the arguments...

Thanks
Copy the command into a text file and name it with the extension .bat.  You can then call this file to run.

Michael
Have a look at this article for more information on setting up the task scheduler

http://richardstk.com/2012/06/15/scheduled-task-to-run-a-batch-file/
Avatar of SW111

ASKER

Thank you Michael.
Just left the office. I will try that when I get back.