I've written a small powershell script that automatically manage the LR backups.
It removes the backups older than "x" days, but always keeps the last "n" backups. These values "x" and "n" are defined in variables "LastMod" and "FilesToKeep" respectively and can be easily changed to meet your need.
On my PC, this script is started automatically every day.
Code:
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Script Suppress LR Backup
# Version 1.2
# Last update : 30/01/2019
#
# Purpose
# =======
# This script will remove all but the n most recent LR catalog backup
# files, providing they are old enough.
# If a backup file has been created less than 30 days ago it won't be
# deleted anyway.
# The number of files to keep is defined in $FilesToKeep
# The oldest aging to keep is defined in $lastmod
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Declaring variables
#$mypath = "S:\Temp\testremove\test"
$mypath = "S:\Sauvegarde\Catalogue_LR"
$FilesToKeep = 5 # Minimume number of files to keep
$jour = Get-Date
$lastmod = $jour.AddDays(-30) # Minimum aging days for the file to be removed
# Suppress all but the "$FilesToKeep" most recent files,
# providing the files are old enough.
$Count = 0
Get-Childitem $mypath -file -recurse | Sort-object LastWriteTime -Descending | Foreach {
$Count = $Count +1
IF ($Count -gt $FilesToKeep) {
IF ($_.LastWriteTime -le "$lastmod") {
# write-host "Deleting File" + $_.fullname -foregroundcolor "Red";
Remove-Item $_.fullname | out-null
}
}
}
# Suppress the empty folders
$ListFolder = Get-Childitem $mypath -Directory -recurse | where { @(gci $_.Fullname).count -eq 0}
Foreach ($Folder in $ListFolder) {
Remove-Item $Folder.Fullname -Recurse | out-null
}
# End of script