Dear Community,<\/p>\n
I googled around and tried different things, but somehow I can’t comprehend what to do here.<\/p>\n
So I have this robocopy bat:<\/p>\n
mkdir s:\\Delete
\nrobocopy c:\\Backup\\Database s:\\Backup /e /MOV /LOG+:c:\\robocopy.log
\nrobocopy s:\\Backup s:\\Delete /e /MOV /MINAGE:14 /LOG+:c:\\robocopy.log
\nrmdir s:\\Delete /s /q<\/p>\n
But executing this command does the following:<\/p>\n
Creates “s:\\Delete”
\nMoves the files from \" c:\\Backup\\Database\" to “s:\\Backup”
\nThen deletes the “.\\Database” and “.\\Delete” Folder with both folders having the files.
\nBut the “.\\Database” folder gets re-created and is empty…<\/p>\n
What am I missing?<\/p>\n
What I want it to do:<\/p>\n
Copy Files from a local folder to a share.
\nThen copy files from the share folder to a temp folder, but only files older than 14 days.
\nThen remove the temp folder.<\/p>\n
Sorry if this is kind of obvious…<\/p>\n
Kind regards,<\/p>\n
xbaloox<\/p>","upvoteCount":3,"answerCount":9,"datePublished":"2020-08-06T05:39:20.000Z","author":{"@type":"Person","name":"xbaloox","url":"https://community.spiceworks.com/u/xbaloox"},"acceptedAnswer":{"@type":"Answer","text":"
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. Dear Community,<\/p>\n I googled around and tried different things, but somehow I can’t comprehend what to do here.<\/p>\n So I have this robocopy bat:<\/p>\n mkdir s:\\Delete But executing this command does the following:<\/p>\n Creates “s:\\Delete” What am I missing?<\/p>\n What I want it to do:<\/p>\n Copy Files from a local folder to a share. Sorry if this is kind of obvious…<\/p>\n Kind regards,<\/p>\n xbaloox<\/p>","upvoteCount":3,"datePublished":"2020-08-06T05:39:21.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/1","author":{"@type":"Person","name":"xbaloox","url":"https://community.spiceworks.com/u/xbaloox"}},{"@type":"Answer","text":" Thank you jrp78! I’m making a scheduled task and it’s done! But just to be sure, do you know why my bat file didn’t work?<\/p>","upvoteCount":1,"datePublished":"2020-08-06T12:42:16.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/3","author":{"@type":"Person","name":"xbaloox","url":"https://community.spiceworks.com/u/xbaloox"}},{"@type":"Answer","text":" I think<\/em> it’s because your command is saying move the contents inside the database folder, not the folder itself.<\/p>","upvoteCount":1,"datePublished":"2020-08-06T12:51:57.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/4","author":{"@type":"Person","name":"jrp78","url":"https://community.spiceworks.com/u/jrp78"}},{"@type":"Answer","text":" Hmm Okay. So thank you. 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.<\/p>\n 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?<\/p>\n Just be cautious when using /MOV and especially /MIR and /PURGE.<\/p>","upvoteCount":2,"datePublished":"2020-08-07T02:23:30.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/6","author":{"@type":"Person","name":"michaelmtallman","url":"https://community.spiceworks.com/u/michaelmtallman"}},{"@type":"Answer","text":" Thank you for the tip!<\/p>\n Yeah sorry for that, I basically meant “Cut/insert”. Yes, first move the files and then delete older than 14 days.<\/p>\n I just thought using /MOV will “delete” all files but not the folder.<\/p>\n That’s the only script I use on this system and there’s no other job active.<\/p>\n Thank you for your help!<\/p>\n Much appreciated<\/p>","upvoteCount":1,"datePublished":"2020-08-07T04:27:18.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/7","author":{"@type":"Person","name":"xbaloox","url":"https://community.spiceworks.com/u/xbaloox"}},{"@type":"Answer","text":" 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 Oh, and welcome to Spiceworks! Good Times Thank you!<\/p>","upvoteCount":0,"datePublished":"2020-08-07T10:05:42.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/9","author":{"@type":"Person","name":"xbaloox","url":"https://community.spiceworks.com/u/xbaloox"}}]}}
\nedit: if you want to remove the database directory from the source folder then add step #3<\/span><\/p>\nREM Copy files from local to share\nrobocopy c:\\Backup\\Database s:\\Backup /e /MOV /LOG+:c:\\robocopy.log\n\nREM Delete files older than 14 days\nforfiles /p \"s:\\Backup\" /d -14 /c \"cmd /c if @isdir==FALSE del /q @file\"\n\nREM Delete the database folder from the source\nrd /S /Q c:\\Backup\\Database\n\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2020-08-06T07:26:53.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/2","author":{"@type":"Person","name":"jrp78","url":"https://community.spiceworks.com/u/jrp78"}},"suggestedAnswer":[{"@type":"Answer","text":"
\nrobocopy c:\\Backup\\Database s:\\Backup /e /MOV /LOG+:c:\\robocopy.log
\nrobocopy s:\\Backup s:\\Delete /e /MOV /MINAGE:14 /LOG+:c:\\robocopy.log
\nrmdir s:\\Delete /s /q<\/p>\n
\nMoves the files from \" c:\\Backup\\Database\" to “s:\\Backup”
\nThen deletes the “.\\Database” and “.\\Delete” Folder with both folders having the files.
\nBut the “.\\Database” folder gets re-created and is empty…<\/p>\n
\nThen copy files from the share folder to a temp folder, but only files older than 14 days.
\nThen remove the temp folder.<\/p>\n
\nThat solution worked flawlessly.<\/p>\n<\/p>\n
\nYour solution is better either way.<\/p>\n<\/p>","upvoteCount":1,"datePublished":"2020-08-06T12:54:11.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/5","author":{"@type":"Person","name":"xbaloox","url":"https://community.spiceworks.com/u/xbaloox"}},{"@type":"Answer","text":"
<\/p>\n
I still use it to back up my laptop files to an external drive.<\/p>\n
<\/p>","upvoteCount":1,"datePublished":"2020-08-07T07:33:48.000Z","url":"https://community.spiceworks.com/t/robocopy-delete-files-older-than-x/771619/8","author":{"@type":"Person","name":"michaelmtallman","url":"https://community.spiceworks.com/u/michaelmtallman"}},{"@type":"Answer","text":"
<\/p>\n