Dear Community,

I googled around and tried different things, but somehow I can’t comprehend what to do here.

So I have this robocopy bat:

mkdir s:\Delete
robocopy c:\Backup\Database s:\Backup /e /MOV /LOG+:c:\robocopy.log
robocopy s:\Backup s:\Delete /e /MOV /MINAGE:14 /LOG+:c:\robocopy.log
rmdir s:\Delete /s /q

But executing this command does the following:

Creates “s:\Delete”
Moves the files from " c:\Backup\Database" to “s:\Backup”
Then deletes the “.\Database” and “.\Delete” Folder with both folders having the files.
But the “.\Database” folder gets re-created and is empty…

What am I missing?

What I want it to do:

Copy Files from a local folder to a share.
Then copy files from the share folder to a temp folder, but only files older than 14 days.
Then remove the temp folder.

Sorry if this is kind of obvious…

Kind regards,

xbaloox

3 Spice ups

You can avoid a bunch of steps by doing it like so. You may need one more step but I’m not 100% clear on what you need. I would just try this first then let us know the result.
edit: if you want to remove the database directory from the source folder then add step #3

REM Copy files from local to share
robocopy c:\Backup\Database s:\Backup /e /MOV /LOG+:c:\robocopy.log

REM Delete files older than 14 days
forfiles /p "s:\Backup" /d -14 /c "cmd /c if @isdir==FALSE del /q @file"

REM Delete the database folder from the source
rd /S /Q c:\Backup\Database

1 Spice up

Thank you jrp78!
That solution worked flawlessly.

I’m making a scheduled task and it’s done! :slight_smile:

But just to be sure, do you know why my bat file didn’t work?

1 Spice up

I think it’s because your command is saying move the contents inside the database folder, not the folder itself.

1 Spice up

Hmm Okay.
Your solution is better either way.

So thank you. :slight_smile:

1 Spice up

Going forward, to test any robocopy job, use the /L switch and it was run as if it was doing the job, minus moving/deleting/copying/et al. Great troubleshooting tool.

Also, I’ve been trying to figure out what was going wrong, with no luck. First of all, you say “copy” yet you execute a “/MOV” - are you moving the files FIRST then doing your older than 14-day operation? The only thing I can think that is happening is that your second line isn’t executing right. Btw, /MOV will delete the source, since you’re moving ALL the files from .\database to s:\backup, I think that is what is happening there - you’re moving the folder, it might execute the delete after all files have been copied. The .\database folder probably gets recreated, I’m guessing, due to a completely different job perhaps?

Just be cautious when using /MOV and especially /MIR and /PURGE.

2 Spice ups

Thank you for the tip!

Yeah sorry for that, I basically meant “Cut/insert”. :smiley:

Yes, first move the files and then delete older than 14 days.

I just thought using /MOV will “delete” all files but not the folder.

That’s the only script I use on this system and there’s no other job active.

Thank you for your help!

Much appreciated

1 Spice up

No problem! I’ve been using robocopy for two decades now and I learned about /MIR very early in that time period, luckily I didn’t lose my job :wink: I still use it to back up my laptop files to an external drive.

Oh, and welcome to Spiceworks! :slight_smile:

1 Spice up

Good Times :smiley:

Thank you!