Solved

Batch Script to copy and remove files from one directory to another

Posted on 2011-03-21
9
258 Views
Last Modified: 2012-05-11
Need to do the following:

1) Local Disk: C://users/administrator/backup
2) Network Drive: Z//backup/production

Need to run a Batch script which simply Runs daily and COPIES all the files from Local Disk C TO Network drive Z. It also removes all the files from Local Disk C when the files have been copied successfully and Appends the new files to the Network Drive on a daily basis.

thanks.
0
Comment
Question by:timerack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 22

Accepted Solution

by:
chakko earned 168 total points
ID: 35180167
how about this:

move C:\users\administrator\backup\*.*  Z:\backup\production\  /Y


/Y is to overwrite is destination folder has a same file already.
0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35180243
Is this a Windows environment?

1) Local Disk: C://users/administrator/backup
2) Network Drive: Z//backup/production

I do not recognize the slashes (/) - would be backslash (\) in Windows.

If this is windows:

Make a short batchfile:

Use xcopy with appropriate flags to copy files and directories
Use del with appropriate flags to delete copied files.

I assume that the files have different names from day to day - otherwise you have to deal with that as well not to lose information by overwriting.

The spec of what you want to achieve has to be more specific!
0
 
LVL 3

Assisted Solution

by:ssisworo
ssisworo earned 166 total points
ID: 35180340
try this.....


-----------------------------------

@echo off

echo ####### Renaming backup for safety
move /y "C:\users\administrator\backup" "C:\users\administrator\backupmove"

echo ####### Create new backup
md "C:\users\administrator\backup"

echo ####### Backup backup
xcopy /s /c /d /e /h /i /r /y "C:\users\administrator\backupmove" "z:\backup\production"

echo ####### Remove backupmove after Backup
RD /s /q "C:\users\administrator\backupmove"

echo ####### Backup and Delete Complete!
@pause


------------------------
0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 5

Assisted Solution

by:xylog
xylog earned 166 total points
ID: 35180828
Robocopy can do this in one command:

robocopy C:\users\administrator\backup Z:\backup\production /e /move

You can schedule it with task scheduler or the at command:

at 23:00 /every:M,T,W,Th,F cmd /c robocopy C:\users\administrator\backup Z:\backup\production /e /move

Please note that using a mapped drive in a scheduled task is tricky. You will likely have trouble with the drive letter. A UNC path might work instead but you would need to make sure that the account that is running the task has sufficient privileges to access that share.

For the AT command there is some info here: http://support.microsoft.com/kb/q158825/

Otherwise you can try using the Task Scheduler which allows you to specify an individual user account to use for running your command.

0
 
LVL 2

Expert Comment

by:ghemstrom
ID: 35180867
Does Windows server 2003 contain robocopy? SSisworo is anyway correct about his part and XYLOG about scheduling
0
 
LVL 5

Expert Comment

by:xylog
ID: 35182533
Robocopy is a free download here as part of the  Windows Server 2003 Resource Kit Tools -> http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

0
 

Author Comment

by:timerack
ID: 35373574
Thanks everyone for the response. I am reviewing it and will get back to you guys soon.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 35994277
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

687 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