AKZN Notes

Archives for My Lazy and Forgetful Mind

Manual Rsync Backup from VPS to Local (with Exclusions)

Rsync Backup from VPS to Local (with Exclusions)

Command

rsync -avz -e "ssh -p 2222" \
  --exclude='node_modules' \
  --exclude='vendor' \
  --exclude='.env' \
  user@vps:/path/app/ /home/youruser/backup/app/

Explanation

Basic flags

  • -a → archive mode (preserve permissions, symlinks, etc.)
  • -v → verbose (show progress)
  • -z → compress during transfer (faster over network)
  • -e "ssh -p 2222" → use SSH with custom port

Excluded folders/files

  • node_modules

    • Large, can be reinstalled (npm install)
  • vendor

    • PHP dependencies, can be restored (composer install)
  • .env

    • Contains secrets (DB, API keys)

Notes

Why exclude dependencies

  • Reduce backup size
  • Faster transfer
  • Rebuildable from lock files (package-lock.json, composer.lock)

About .env

  • Excluded by default (recommended)

    • Avoid leaking credentials
  • If needed for full restore:

    • Backup separately
    • Store securely (encrypted or private location)

Result

  • Clean backup of app source code
  • Smaller size
  • Faster sync
  • Safer (no secrets included)
Categories: VPS