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

x
?
Solved

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

Posted on 2013-12-18
12
Medium Priority
?
3,954 Views
Last Modified: 2013-12-27
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.
0
Comment
Question by:SW111
  • 6
  • 6
12 Comments
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 39728464
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
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 39728471
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
0
 

Author Comment

by:SW111
ID: 39728566
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
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 

Author Comment

by:SW111
ID: 39728638
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
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 39730763
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
0
 

Author Comment

by:SW111
ID: 39731102
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
0
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 total points
ID: 39737180
Sorry for delay

The flags are specifying that we are coying a directory so we do not need to include the back slashes and when a single file is specified the message you noted appears because the system is expecting a directory but got a single file.

I have tested the following and it worked for me (X's replace actual server name)

Xcopy /S /I /E /H "C:\tmp" "\\XXXXXXXXX\Test Share\test-%date:~4,2%-%date:~7,2%-%date:~10,4%_@_%time:~0,2%h%time:~3,2%m%time:~6,2%s%"

so for you it should be

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%"

Michael
0
 

Author Comment

by:SW111
ID: 39741078
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!
0
 

Author Comment

by:SW111
ID: 39741090
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
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 39741094
Copy the command into a text file and name it with the extension .bat.  You can then call this file to run.

Michael
0
 
LVL 23

Expert Comment

by:Michael Fowler
ID: 39741096
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/
0
 

Author Comment

by:SW111
ID: 39741360
Thank you Michael.
Just left the office. I will try that when I get back.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VM backup deduplication is a method of reducing the amount of storage space needed to save VM backups. In most organizations, VMs contain many duplicate copies of data, such as VMs deployed from the same template, VMs with the same OS, or VMs that h…
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question