?
Solved

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

Posted on 2011-03-21
9
Medium Priority
?
259 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 672 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 664 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
LVL 5

Assisted Solution

by:xylog
xylog earned 664 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

771 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