Solved

Robocopy overcleans - help!

Posted on 2013-11-20
10
479 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
[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
  • 5
  • 3
  • 2
10 Comments
 
LVL 85

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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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 85

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 85

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
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 setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

635 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