Automate compression of Lightroom Backups

Bender.oh

Suspended / Banned
Messages
14
Edit My Images
Yes
Having found out that Lightroom does no housekeeping on its backup files I decide to write a small Windows Powershell script to automate the compression and deletion of these backups.

With my backups I am getting a 50x saving in space, 110Mb backup compresses to 2Mb.

This routine uses 7Zip to do the compression so that has to be installed on your machine.
Code:
# Check to see the 7zip is installed
if (-not (test-path "$env:ProgramFiles\7-Zip\7z.exe")) {
    throw "$env:ProgramFiles\7-Zip\7z.exe needed"
    }

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"

# Create a collection to the lightroom backup folder
$folders = Get-ChildItem "D:\Users\Bender\Pictures\Lightroom\Backups" | where { $_.PSISContainer }

foreach ($folder in $folders) {
#  compress the folder
    sz a -t7z $folder.fullname $folder.FullName

    $folderitems = $folder.FullName + "\*"
#  delete the files in the backup folder -    *** remove this line if you don't want your backup deleted ***
    remove-item $folderitems
# delete the backup folder -  *** remove this line if you don't want your backup deleted ***
    remove-item $folder.FullName
}

To create this script
  • create a file with a .ps1 suffix,
  • copy the code above into this file,
  • change the line containing D:\Users\Bender\Pictures\Lightroom\Backups to the path for your backups,
  • save the file.
To run the script right click the file and choose "Run with Powershell" to start, it is also possible to use the windows scheduler to execute this script on a daily or weekly basis.
 
Back
Top