File sync

2 snippets across 2 stacks — Bash & Linux, Docker

Also written as sync files

SHBash & Linux

Efficient File Synchronization

SH · Networking
syntax
rsync [options] source destination
example
rsync -avz --progress ./build/ deploy@web:/var/www/app/
rsync -avz --delete --exclude='.git' src/ backup/src/
rsync -avz -e 'ssh -p 2222' data/ user@host:/data/

Note -a is archive mode (preserves permissions, timestamps, symlinks). -v is verbose. -z compresses during transfer. --delete removes files from the destination that no longer exist in the source (be careful). Trailing slash on source matters: dir/ syncs contents, dir syncs the directory itself.

DKDocker

Compose Watch (Hot Reload)

DK · Docker Compose
syntax
docker compose watch
# or in compose.yaml:
services:
  api:
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
example
services:
  api:
    build: .
    develop:
      watch:
        - action: sync
          path: ./src
          target: /app/src
        - action: rebuild
          path: package.json
# Then: docker compose watch

Note sync copies changed files into the container without rebuilding. rebuild triggers a full image rebuild when the specified file changes (e.g., when you add a dependency). This replaces many custom file-watching setups.