#!/bin/bash # Define the iCloud Drive backup directory ICLOUD_BACKUP_DIR="$HOME/Library/Mobile Documents/com~apple~CloudDocs/GitBackups" # Create the backup directory if it doesn't exist mkdir -p "$ICLOUD_BACKUP_DIR" # Get the name of the current repo REPO_NAME=$(basename "$(git rev-parse --show-toplevel)") # Create a timestamped backup TIMESTAMP=$(date "+%Y-%m-%d_%H-%M-%S") BACKUP_DIR="$ICLOUD_BACKUP_DIR/${REPO_NAME}_backup_$TIMESTAMP" # Copy the repo to iCloud Drive rsync -av --exclude='.git' "$(git rev-parse --show-toplevel)/" "$BACKUP_DIR" # Optional: Log the backup echo "Backup created at $BACKUP_DIR" >> "$ICLOUD_BACKUP_DIR/backup_log.txt" exit 0