← All writing
 ·  1 min read

Back Up Your Dev Folder on macOS with rsync

Use rsync on your Mac to efficiently back up your project folder while skipping unnecessary files like node_modules, vendor, logs, and caches.

Back Up Your Dev Folder on macOS with rsync

As a PHP developer, I use rsync on my Mac to efficiently back up project folders while skipping unnecessary files like node_modules, vendor, logs, and caches. I try to follow the 1-2-3 rule for backups: Github/cloud (1), local development machine (2), and external hard drive (3).

Here’s how I back up to an external hard drive in a single command (you might want to modify the command if you plan to keep files like .env or a folder like .git):

bash
rsync -avh --progress \
  --exclude '.git/' \
  --exclude '.env' \
  --exclude '.env.*' \
  --exclude '.DS_Store' \
  --exclude 'node_modules/' \
  --exclude 'vendor/' \
  --exclude 'composer.lock' \
  --exclude 'package-lock.json' \
  --exclude 'yarn.lock' \
  --exclude 'logs/' \
  --exclude '*.log' \
  --exclude 'cache/' \
  --exclude 'tmp/' \
  --exclude 'temp/' \
  --exclude 'build/' \
  --exclude 'dist/' \
  --exclude 'public/build/' \
  --exclude 'public/assets/' \
  --exclude '.vscode/' \
  --exclude '.idea/' \
  --exclude 'npm-debug.log' \
  --exclude 'yarn-error.log' \
  --exclude 'coverage/' \
  --exclude 'tests/_output/' \
  --exclude 'storage/framework/' \
  --exclude 'storage/logs/' \
  --exclude 'storage/cache/' \
  --exclude '.phpunit.result.cache' \
  --exclude 'bower_components/' \
  --exclude '*.bak' \
  --exclude '*.swp' \
  --exclude '*.swo' \
  --exclude 'Thumbs.db' \
  ~/Projects/my-app/ /Volumes/Backups/

And if I need long-term cold storage, I use DVDs.