Skip to content

Instantly share code, notes, and snippets.

@koriym
Created July 16, 2025 03:43
Show Gist options
  • Select an option

  • Save koriym/8a6e4bbf786ca35d1032201275a6f221 to your computer and use it in GitHub Desktop.

Select an option

Save koriym/8a6e4bbf786ca35d1032201275a6f221 to your computer and use it in GitHub Desktop.
Backup brew settings
#!/bin/bash
# バックアップファイルの保存先
BACKUP_DIR=~/brew-backup
mkdir -p "$BACKUP_DIR"
echo "📦 Saving installed formulae..."
brew list > "$BACKUP_DIR/formula-list.txt"
echo "🧃 Saving installed casks..."
brew list --cask > "$BACKUP_DIR/cask-list.txt"
echo "🌐 Saving tapped repositories..."
brew tap > "$BACKUP_DIR/tap-list.txt"
echo "✅ Backup complete. Files saved in $BACKUP_DIR"
# 復元用スクリプト作成
cat <<'EOF' > "$BACKUP_DIR/brew-restore.sh"
#!/bin/bash
echo "🔁 Restoring Homebrew environment..."
echo "📥 Re-tapping repositories..."
xargs brew tap < ~/brew-backup/tap-list.txt
echo "📦 Installing formulae..."
xargs brew install < ~/brew-backup/formula-list.txt
echo "🧃 Installing casks..."
xargs brew install --cask < ~/brew-backup/cask-list.txt
echo "✅ Restoration complete."
EOF
chmod +x "$BACKUP_DIR/brew-restore.sh"
echo "📝 To restore your Homebrew setup later, run:"
echo "bash $BACKUP_DIR/brew-restore.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment