Solved

Robocopy overcleans - help!

Posted on 2013-11-20
10
473 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 83

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 83

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 83

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

Problems using Powershell and Active Directory?

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

OfficeMate Freezes on login or does not load after login credentials are input.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …

776 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