Using Robocopy to keep folders clean

SQL server has always had difficulty with its backup and maintenance plans in removing old backups. Until now this has been a major issue on some of our servers, each month someone has to go through the backup folder and remove the old Transaction Log and Full Backup folders. No longer – Robocopy to the […]
Last updated: March 12, 2012

SQL server has always had difficulty with its backup and maintenance plans in removing old backups. Until now this has been a major issue on some of our servers, each month someone has to go through the backup folder and remove the old Transaction Log and Full Backup folders. No longer – Robocopy to the rescue! Its simple but oh so efficient. (I know there are many different ways to do this, Perl/ANT etc however this is what I have available on the server)

By simply copying the files over to a temp folder, robocopy has some switches that allow us to tell it to MOVE the files that have a timestamp older than a certain number of days, once its done its work, we simply delete the temp folder and all those old files are gone. One added bonus here is the logging, we can tell what was moved, and therefore deleted. This one uses the Standard SQL install path, careful of those funky ~1 DOS path names though, it took me a few minutes to get those right. All the command should be on one line too. Save it as cleanup.bat or something similar, double click and you are away!

You can download and install Robocopy as part of the Windows Server 2003 Resource Kit Tools And read about the many different things robocopy can do for you.

Duncan Isaksen-Loxton

Educated as a web developer, with over 20 years of internet based work and experience, Duncan is a Google Workspace Certified Collaboration Engineer and a WordPress expert.
Login
Log in below to access your courses.
Log In With Google
Forgot Password
Enter your email address or username and we’ll send you instructions to reset your password.