Solved

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

Posted on 2011-03-21
9
253 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
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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 68

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Read about why website design really matters in today's demanding market.
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now