Solved

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

Posted on 2011-03-21
9
256 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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 69

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
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:
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

828 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