Untitled
unknown
plain_text
a year ago
3.2 kB
12
Indexable
#!/bin/bash
# Define backup directory
BACKUP_DIR=~/Desktop/MacBackup_$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"
echo "Backing up installed applications list..."
# List applications in /Applications
ls /Applications > "$BACKUP_DIR/InstalledApps.txt"
# List user-specific applications
if [ -d ~/Applications ]; then
ls ~/Applications >> "$BACKUP_DIR/InstalledApps.txt"
fi
# Use Spotlight to find all applications
mdfind "kMDItemKind == 'Application'" > "$BACKUP_DIR/AllApps.txt"
echo "Backing up application settings and preferences..."
# Backup Preferences
cp -a ~/Library/Preferences "$BACKUP_DIR/Preferences"
# Backup Application Support
cp -a ~/Library/Application\ Support "$BACKUP_DIR/Application Support"
# Backup Containers (for sandboxed apps)
cp -a ~/Library/Containers "$BACKUP_DIR/Containers"
echo "Backing up Launch Agents and Daemons..."
# Backup Launch Agents and Daemons
mkdir -p "$BACKUP_DIR/LaunchAgents/System"
mkdir -p "$BACKUP_DIR/LaunchDaemons/System"
mkdir -p "$BACKUP_DIR/LaunchAgents/User"
cp -a /Library/LaunchAgents "$BACKUP_DIR/LaunchAgents/System"
cp -a /Library/LaunchDaemons "$BACKUP_DIR/LaunchDaemons/System"
cp -a ~/Library/LaunchAgents "$BACKUP_DIR/LaunchAgents/User"
echo "Listing Login Items..."
# Get Login Items (macOS 10.13 High Sierra and later)
osascript -e 'tell application "System Events" to get the name of every login item' > "$BACKUP_DIR/LoginItems.txt"
echo "Backing up Homebrew packages..."
# Check if Homebrew is installed
if command -v brew &> /dev/null; then
brew list --formulae > "$BACKUP_DIR/BrewFormulae.txt"
brew list --casks > "$BACKUP_DIR/BrewCasks.txt"
fi
echo "Backing up personal files..."
# List of personal directories to backup
PERSONAL_DIRS=("Documents" "Downloads" "Desktop" "Pictures" "Music" "Movies")
for DIR in "${PERSONAL_DIRS[@]}"; do
if [ -d ~/"$DIR" ]; then
echo "Backing up $DIR..."
cp -a ~/"$DIR" "$BACKUP_DIR/"
fi
done
echo "Exporting Safari bookmarks..."
# Export Safari bookmarks
if [ -f ~/Library/Safari/Bookmarks.plist ]; then
cp ~/Library/Safari/Bookmarks.plist "$BACKUP_DIR/SafariBookmarks.plist"
fi
echo "Exporting Chrome bookmarks..."
# Export Chrome bookmarks
if [ -d ~/Library/Application\ Support/Google/Chrome ]; then
mkdir -p "$BACKUP_DIR/Chrome"
cp -a ~/Library/Application\ Support/Google/Chrome/Default/Bookmarks "$BACKUP_DIR/Chrome/Bookmarks"
fi
echo "Exporting Firefox bookmarks..."
# Export Firefox bookmarks
if [ -d ~/Library/Application\ Support/Firefox ]; then
PROFILE_PATH=$(ls -d ~/Library/Application\ Support/Firefox/Profiles/*.default-release 2>/dev/null)
if [ -n "$PROFILE_PATH" ]; then
mkdir -p "$BACKUP_DIR/Firefox"
cp -a "$PROFILE_PATH"/bookmarkbackups "$BACKUP_DIR/Firefox/"
fi
fi
echo "Collecting software license information..."
# This step is largely manual; the script can attempt to gather some license files
LICENSE_DIRS=("~/Library/Preferences" "~/Library/Application Support")
for DIR in "${LICENSE_DIRS[@]}"; do
find "$DIR" -type f \( -name "*license*" -o -name "*.plist" \) -print0 2>/dev/null | xargs -0 -I {} cp -a {} "$BACKUP_DIR/Licenses/"
done
echo "Backup completed. Backup directory is located at $BACKUP_DIR"Editor is loading...
Leave a Comment