Solved

Robocopy overcleans - help!

Posted on 2013-11-20
10
476 Views
Last Modified: 2013-11-21
Here's what I'm trying to do. Move SQL BAK files older than 2 days from a Bakup folder to a Restore folder and then move folders older than 7 days to Kill Me and then delete the files permanently. This will run overnight to ensure that the Backup folder has all the files younger than 2 days (includes BAK, DFF, TRN, etc.), the BAK files between 2-7 days old are stored somewhere (Restore) and all BAK files over 7 days old are dekleted.

Here's the batch code I created.

robocopy U:\Backup U:\Restore /MIR /MOV /MINAGE:2 /LOG+:"u:\Backup\BackDatUp.txt" /z /np

robocopy U:\Restore U:\KillMe /MIR /MOV /MINAGE:7 /LOG+:"u:\Backup\BackDatUp.txt" /z /np

del U:\KillMe /q /LOG+:"u:\Restore\BackDatUp.txt" /z /np

Problem of course is that the BAK files in Restore are overwritten and I don't even get to the Kill Me portion becuase no file is over 7 days.

How do I move the BAK files from Backup to Restore without overwriting Restore. The folder has a separate folder for every DB.
0
Comment
Question by:fsbpt
  • 5
  • 3
  • 2
10 Comments
 
LVL 84

Expert Comment

by:oBdA
ID: 39663963
Remove the /mir from your command lines. /mir mirrors the source directory (that is, it deletes files in the target which don't exist in the source), which is not what you want.
You're getting rid of all files by way of /mov, not by /mir.
0
 
LVL 22

Expert Comment

by:Nick Rhode
ID: 39663966
I believe the /MIR option is what is doing it to you.  What that will do is mirror that folder so that means the files in that location will get deleted and the new ones will replicate.
0
 

Author Comment

by:fsbpt
ID: 39663992
Do I need something instead of the /MIR? If I remove the /MIR it doesn't move anything.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 22

Expert Comment

by:Nick Rhode
ID: 39664041
The /MOV switch should copy the files the delete from the source when the copy action completes.

It looks a little garbled (the script).  Kind of rusty with robocopy but shouldn't it be something like /S /MOV
0
 

Author Comment

by:fsbpt
ID: 39664054
maybe I need to change /MOV to /MOVE. I just don't to actually delete any directories from my original location - just the files.
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39664155
/move will not only move files, but the folders as well.
/mov should do the trick for you; for testing, note the /L argument, which only shows the files it would copy, but not actually do anything.
0
 

Author Comment

by:fsbpt
ID: 39664198
Thanks guys. oBdA I will try that tomorrow as I have not more files to move unless I copy them back. Oh maybe I'll try that. Thanks.
0
 

Author Comment

by:fsbpt
ID: 39666425
Here's the final Batch Code... Testing it now.

REM This Robocopy Job will move files older than 2 days from Bakup to Restore
REM and move files older than 7 days to a temporary folder and then delete it

robocopy U:\Backup U:\Restore /E /MOVE /MINAGE:2 /LOG+:"u:\backup\BackDatUp.txt" /z /np /tee

REM /L (lists - doesn't move) /np (no progress)

MD U:\KillMe

robocopy U:\Restore U:\KillMe /E /MOVE /MINAGE:7 /LOG+:"u:\Backup\BackDatUp.txt" /z /np /tee

RD U:\KillMe /S /Q
0
 
LVL 84

Expert Comment

by:oBdA
ID: 39667059
One more hint: if you're really running the "RD U:\KillMe /S /Q" directly after the robocopy, you could add /create to the options of the robocopy command that moves the files into the KillMe folder. /create will create only empty files (it's usually used to pre-create a folder structure to prevent the MFT from partioning), but still delete the source files after the zero-byte files have been created. This can save some disk activity and time if you have huge databases.
0
 

Author Comment

by:fsbpt
ID: 39667129
where would that go?


REM This Robocopy Job will move files older than 2 days from Bakup to Restore
REM and move files older than 7 days to a temporary folder and then delete it

robocopy U:\Backup U:\Restore /E /MOVE /MINAGE:2 /LOG+:"u:\backup\BackDatUp.txt" /z /np /tee

REM /L (lists - doesn't move) /np (no progress)

MD U:\KillMe

robocopy U:\Restore U:\KillMe /create /E /MOVE /MINAGE:7 /LOG+:"u:\Backup\BackDatUp.txt" /z /np /tee

RD U:\KillMe /S /Q
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

726 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