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
Solved

Robocopy overcleans - help!

Posted on 2013-11-20
10
475 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
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…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

829 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