You use Lightroom a lot and create backups of your catalog on a regular basis. Chances are that those backups have started filling your hard drive. This article will show you how to automate the process to delete old Lightroom backups. The most important recent backups will remain untouched.

In this article you will learn to create a script which will identify and delete old Lightroom backups.

The script will allow you to define how many of your most recent catalog backups will remain on your hard drive. You can still restore your catalog in case it gets corrupted. The advantage is that your hard drive will no longer fill up with unused old catalog backups.

Disclaimer: This article assumes that you have at least some understanding of scripting. If you don’t feel comfortable to follow the instructions below, please ask someone with appropriate knowledge to assist you. You are implementing this solution at your own risk. I am not responsible for loss of data caused by inappropriate use of this script.

Cleaning up Lightroom catalog backups

To create the script file and adjust it to your needs, follow these simple steps:

Create the script file

  1. Copy the content of the script below and paste the code into Notepad or any other text editor of your choice
  2. Save the file with an extension of .cmd or .bat, for example CleanupLRBackups.cmd
@echo off
rem Adjust the folder below to match your environment
pushd "%USERPROFILE%\Pictures\Lightroom\Backups"
rem Adjust the 5 in skip=5 to the number of folders you would like to keep
for /f "skip=5 delims=" %%a in ('dir /b /o-d /ad') do echo rd /s /q "%%a"
rem Remove the next line if you don't want the script to pause before it ends

Adjust the script to your environment

There are two areas in the script that you need to adjust to your personal environment (marked in red):

      1. In line 4, after the pushd comment, you need to enter the path of your Lightroom catalog backups folder. The example in the script above will likely not work on your Personal Computer. You don’t know where your Lightroom backups are stored? In Lightroom, go to the catalog settings and set the backup frequency to “When Lightroom next exits”. Now exit Lightroom and look at the backup dialog that pops up:
        Screenshot of the Lightroom Back Up Catalog dialog
        Take note of the Backup Folder location

        You will find the backup folder location right below the Back up catalog frequency drop-down. Replace the red part of line 4 with your backup folder name, make sure you keep the double quotes.

        You can also use UNC notation if your backup folder is located on a network device. For example, "\\YourNAS\Share\Folder" is a perfectly valid folder name. This is why we are using the pushd command here.

      2. In line 7, replace the 5 in "skip=5 delims=" with the number of recent backups you would like to keep. For example, if you would like to keep the 10 most recent backups, change it to: "skip=10 delims=". Again, make sure you keep the double quotes. Save the changes.

Test the script

Be aware that at this point, the script will actually not delete anything. It will just report which folders it would have deleted. We will use this to test if the script works correctly.

In Windows Explorer, double-click on the script file to execute it. You should see a window with content like this:

Screenshot of the script test output
Script test output

Your output will likely differ in the number of lines. The important thing here is to note which folders would have actually been deleted (the part in double quotes). You might have to scroll up to see the complete list. Now compare this list with the Explorer view of your Lightroom catalog backup folder. Ideally, the most recent folders you wanted to exclude do not show up in the output list.

After you have confirmed that the output matches your expectation, you can move to the next step. If you see an error message, please go back and check the script file for typos.

Remove the safeguards

Now that you are confident that the script will run correctly, it is time to remove the safeguards. For that, we need to remove the parts marked above in blue:

  1. In line 7, remove the word echo from do echo rd /s /q "%%a" at the end of the line so it reads do rd /s /q "%%a".
  2. If you want, you can remove line 10 (the pause command) completely. The script output window will close itself after it has completed. If you would rather verify what the script did, you can remove line 1 (the @echo off command) instead. The output window will show you each step in detail.

This is it. Every time you want to delete old Lightroom backups, double-click the script file. I hope you find this article helpful, for sure it helped me to free up a lot of space on my hard drive. You can find additional helpful tips in the Photography How and Why section.

Automate the process

You can automate the process to delete old Lightroom backups. For that, use the Windows Task Scheduler to create a new job and run your script file for example weekly or monthly. Detailed instructions are currently not part of this post. But if you would like to know how to do this, please leave a comment below and I will update the article.

To credit the original author: I found the basis for this script on Stack Overflow.

A simpler alternative: Lightroom Backup Cleaner plugin

You find the above solution too complex or use Lightroom for MacOS? You may want to check out the Lightroom Backup Cleaner plugin. It already supports Lightroom Classic CC, and you configure it from within Lightroom. It is not free, but available for a very reasonable amount.

I have not used the plugin myself, and I am also not affiliated with the plugin. I have only included the reference for your convenience.

Header photo by Samuel Zeller on Unsplash