Automated Strategies for Managing Outdated Backup Files

Backups are something which, usually, run on a very frequent schedule. If left unmanaged, a direct result of this is a large number files eating up a potentially large amount of hard drive space. Remembering to manually go in and remove backup files certainly is one method of management but shouldn’t be a long term strategy, especially when there are easy to implement automated procedures available.

There is no ‘one size fits all’ solution for automating the process of deleting expired backup files. Depending on the backup procedure (do you do weekly full and daily incrementals or daily full?) and file naming convention (does your backup file have the date as part of the file name or use the same file name every time?) of your resulting backup files, the applicable method differs.

We are going to point out several simple solutions which fit the most common backup scenarios, so odds are one will be right for you.

Deleting by File Age or Date

When to use: Daily full backups.

Perhaps the simplest and most logical way to purge expired backups is to base the deletion process on the date of the backup file. We have previously covered this topic using log files as our target files, however it works just as well with backup files.

For example, to delete any files in the specified folder not modified within the past week, run this command:

FORFILES /P “C:Backups” /S /D -7 /C “CMD /C DEL /F /Q @PATH”

Note the keyword above: modified. The ForFiles command is only capable of evaluating the modified file date as opposed to the created date which would be more applicable. Typically, however, you are probably not modifying a backup file after it is created so this will most likely not be an issue.

Alternately, if your backup file has some sort of numeric date pattern specified in the file name (i.e. Backup_2010-01-13.zip, BackupSet_100113_Full.zip, etc.), you can use the DeleteByDatePattern script we provided in the linked article to remove expired backups.

For example, to delete files older than 2 weeks matching a file name pattern like the following: “Backup_YYYY-MM-DD_(Full | Incremental).zip”, you would use the command:

DeleteByDatePattern /D 15 “C:Backups” *-????-??- _*.zip /DEL

Or if your file naming pattern is: “BackupSet_YYMMDD.zip”, you would use:

DeleteByDatePattern /D 15 “C:Backups” *-???? .zip /DEL

Of course, adjust as needed but either of the methods above could easily be added to the start or end of your backup process to keep the number of backups stored manageable.

Folder Rolling

When to use: Periodic full backups (weekly, bi-weekly, etc.) with daily incremental backups in between.

The idea behind “folder rolling” is that you store all of your current backup set (full backup + respective incrementals) in a single folder and then have several archive folders where your old backup sets are kept. Prior to a new backup set being created, you delete the folder contents containing oldest backup set and “roll” the contents of each folder down one.

For example, suppose we have a current backup folder with two archive folders. The batch script commands to perform the folder roll for this would be:

DEL /F /Q “C:Backups2archive”
MOVE /Y “C:Backups1archive*” “C:Backups2archive”
MOVE /Y “C:Backupscurrent*” “C:Backups1archive”

You can add as many archive folders as needed. Just delete the contents of the lowest archive folder add a move command for each of the other archive folders.

Again, this works best for situations where you create a periodic full backup and the a number of incremental backups up until your next full backup. Simply drop all your related backup files into a single folder and the run the folder roll script right before you create a new backup set.

Backup9

When to use: Daily full backups or individual file backups.

Backup9 is a free command line utility developed by Gammadyne. Similar to the folder rolling process above, the idea behind this utility is simple in that when it is run, a copy of the target file is created with a number appended to the end. Additionally, you specify a cut-off of the number of copies to keep with the default being 9 (hence the name).

An example will best explain this process. Using the following command would produce the output below:

BACKUP9 /A /L7 “C:BackupsBackupFile.zip”

automated-strategies-for-managing-outdated-backup-files photo 1

automated-strategies-for-managing-outdated-backup-files photo 2

If this command were run again, the following would happen:

  1. The number of files to keep (7 in our example) is evaluated and if there are currently that many copies, the last one is dropped.
  2. BackupFile.zip.bk7 is deleted.
  3. BackupFile.zip.bk6 is renamed to BackupFile.zip.bk7
  4. BackupFile.zip.bk[#] is renamed to BackupFile.zip.bk[#+1]
  5. BackupFile.zip.bk1 is renamed to BackupFile.zip.bk2
  6. BackupFile.zip is copied and named BackupFile.zip.bk1

With the ability to keep up to 999 copies, this utility works very well if you have a file with a static name. You simply add the Backup9 command to the beginning or end of your backup process it takes care of keeping up with the appropriate number of archive copies.

Belvedere Automated File Manager

When to use: Daily full backups.

Belvedere automated file manager is a utility which runs in the background monitoring file system active and performs configured actions when specified conditions are met. Among its many uses are cleaning up expired backup files.

The configuration of the rules are pretty straightforward. For example, to create a rule to delete backup files using a file name pattern such as “BackupSet_Jan13.zip” which are older than 2 weeks, you could use the following:

automated-strategies-for-managing-outdated-backup-files photo 3

While the basic function we are performing can easily be done with command line tools described above, the obvious difference is that Belvedere provides an easy to use graphical interface for those more comfortable with pointing and clicking.

Belvedere is designed as a desktop user application which runs from the system tray, however you can run Belvedere as a service and use it on servers to perform this and other file monitoring operations.

Conclusion

While there are a myriad number of ways you can manage your backup expiration process, the methods we have described above are both flexible and easy to implement. With a bit of experimentation, find what works for you and go with it so you can just set it and forget it.

Links

Download Backup9 from Gammadyne.com

Download Belvedere from Lifehacker.com

More stories

The How-To Geek Guide to Computer Microphones

With Gmail adding the ability to make free calls within the US and Canada, now is a great time to invest in a quality computer microphone. We’ll take some of the guesswork out of that process, and give you some tips on setting up your microphone once you get it.

How To Add Comments to Documents in Word 2010

If you’re sharing or collaborating on a Word document, you might want an easy way to add comments to parts of text. Here we look at how to add comments to documents in Word 2010.

Easily View the Disk Space Usage of Individual SQL Tables in a Database

With any active database, disk storage requirements are going to grow over time. While you can easily view the disk space used by an entire database by either look in the Files page of the database properties in SQL Management Studio or simply viewing the underlying files in Windows Explorer, what

Other Ways to Use Your PC When Your Internet Dies

Nothing is more annoying than getting your Internet connection shut down, due to weather, or perhaps forgetting to pay your bill. Let’s take a look at some ways you can be productive and entertained without the Internet.

Change the Actions for File Types in Opera

Opera is a solid, well built browser that is easy to customize once you become familiar with it. If you want to tweak how Opera handles actions such as viewing images or pdf files without saving them to your computer then here is how to do it.