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):

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.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Involved & Explore More

an abstract painting with blue and yellow colors

Catch up on what I’ve been writing lately.

Show your gratitude.

Join Dare To Code Email List

Get emails from me on full-stack PHP development by subscribing to the Dare To Code mailing list.