Solved

Robocopy overcleans - help!

Posted on 2013-11-20
10
462 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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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
Comment Utility
Do I need something instead of the /MIR? If I remove the /MIR it doesn't move anything.
0
 
LVL 22

Expert Comment

by:Nick Rhode
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
/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
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Are you looking to recover an email message or a contact you just deleted mistakenly? Or you are searching for a contact that you erased from your MS Outlook ‘Contacts’ folder and now realized that it was important.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
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 …
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…

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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now