Skip to content

Instantly share code, notes, and snippets.

@marwanmakm
Created September 18, 2024 19:16
Show Gist options
  • Save marwanmakm/24499f0d568e92e560bd29412faa2068 to your computer and use it in GitHub Desktop.
Save marwanmakm/24499f0d568e92e560bd29412faa2068 to your computer and use it in GitHub Desktop.
Smart Backup Lightroom Data to External Hardrive using rsync in Mac
#!/bin/bash
### Shell Script to Smart Backup the Lightroom Data into a External Hard Drive Disk using rsync
###
### DESCRIPTION: This script locate the two folders related with the Lightroom data (the catalog folder and the photos folder)
### and back it up to a specified external hard drive (or any path) using smart backup with rsync.
###
### DISCLAIMER: This script only creates a exact copy of your current folders and optimize the sync process, it doesn't
### save snapshots or something like that.
###
### By M. Makarem
## DECLARATIONS
# Example
# LIGHTROOM_CATALOG_DIR="/Users/marwanmakm/Documents/Photo Bucket_Catalog"
# PHOTO_DATA_DIR="/Users/marwanmakm/Documents/Photo Bucket"
# BACKUP_DIR="/Volumes/{YOUR HARD DRIVE NAME}/Backup"
# LOG_FILE="/Users/marwanmakm/Documents/backup.log"
LIGHTROOM_CATALOG_DIR="/path/to/folder" # Folder that contains all catalog data to back up
PHOTO_DATA_DIR="/path/to/folder" # Folder that contains photos data to back up
BACKUP_DIR="/Volumes/{YOUR HARD DRIVE NAME}/Backup" # Backup destination
LOG_FILE="/path/to/folder/backup.log" # Log file to keep track of backups
## VALIDATIONS
DIR_LIST=(
"$LIGHTROOM_CATALOG_DIR"
"$PHOTO_DATA_DIR"
)
# Checks if the source directory exists
for DIR in "${DIR_LIST[@]}"
do
echo "Evaluating... $DIR"
if [ ! -d "$DIR" ]; then
echo "ERROR: Source Directory $DIR has not been found"
exit -1
fi
done
# Ensure backup directory exists
if [ ! -d "$BACKUP_DIR" ]; then
mkdir -p "$BACKUP_DIR"
fi
## EXECUTION
# Use rsync to clone the folder (it copies only new or changed files and delete those files that doesn't exists anymore)
rsync -ahP --delete "$LIGHTROOM_CATALOG_DIR" "$PHOTO_DATA_DIR" "$BACKUP_DIR" 2>"$LOG_FILE"
# Log the result
if [ $? -eq 0 ]; then
echo "$(date +"%Y-%m-%d %H:%M:%S"): Successfully synced to $BACKUP_DIR" >>"$LOG_FILE"
else
echo "$(date +"%Y-%m-%d %H:%M:%S"): Sync failed" >>"$LOG_FILE"
fi
# Exit the script
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment