Automatically Syncing Files with rsync
Automatically synchronize files between your local development environment and Workspace Manager workspaces using rsync.
Overview
Section titled “Overview”rsync provides efficient file synchronization, allowing you to work with local files while keeping them in sync with your remote workspace. This is ideal for developers who prefer local editing with remote execution.
Prerequisites
Section titled “Prerequisites”- rsync installed on your local machine
- SSH access configured (see SSH documentation)
- Workspace running and accessible
Basic Usage
Section titled “Basic Usage”Once your SSH configuration is set up, you can use rsync to synchronize files between your local machine and workspace.
Push Local Changes to Workspace
Section titled “Push Local Changes to Workspace”rsync -avz --progress ~/local/project/ wsm.my_workspace:~/project/Pull Workspace Changes to Local
Section titled “Pull Workspace Changes to Local”rsync -avz --progress wsm.my_workspace:~/project/ ~/local/project/Common rsync Options
Section titled “Common rsync Options”-a- Archive mode (preserves permissions, timestamps, symbolic links)-v- Verbose output-z- Compress data during transfer--progress- Show progress during transfer--delete- Delete files in destination that don’t exist in source--dry-run- Preview changes without actually syncing
Sync Strategies
Section titled “Sync Strategies”One-Way Sync (Local to Remote)
Section titled “One-Way Sync (Local to Remote)”Push your local changes to the workspace. This is useful when you edit locally and want to test/run code remotely.
rsync -avz --delete --progress \ --exclude '.git' \ --exclude 'node_modules' \ ~/local/project/ wsm.my_workspace:~/project/The --delete flag ensures files deleted locally are also removed from the workspace.
One-Way Sync (Remote to Local)
Section titled “One-Way Sync (Remote to Local)”Pull workspace changes to your local machine. Useful for retrieving generated files or changes made directly on the workspace.
rsync -avz --progress \ --exclude '.git' \ --exclude 'node_modules' \ wsm.my_workspace:~/project/ ~/local/project/Automatic Synchronization
Section titled “Automatic Synchronization”Using fswatch (macOS)
Section titled “Using fswatch (macOS)”Install fswatch and create a sync script:
brew install fswatchCreate sync-to-workspace.sh:
#!/bin/bashPROJECT_DIR="$HOME/local/project"WORKSPACE="wsm.my_workspace:~/project/"
fswatch -o "$PROJECT_DIR" | while read f; do echo "Changes detected, syncing..." rsync -avz --delete \ --exclude '.git' \ --exclude 'node_modules' \ "$PROJECT_DIR/" "$WORKSPACE"doneMake it executable and run:
chmod +x sync-to-workspace.sh./sync-to-workspace.shUsing inotifywait (Linux)
Section titled “Using inotifywait (Linux)”Install inotify-tools:
# Ubuntu/Debiansudo apt-get install inotify-tools
# Fedora/RHELsudo dnf install inotify-toolsCreate a sync script:
#!/bin/bashPROJECT_DIR="$HOME/local/project"WORKSPACE="wsm.my_workspace:~/project/"
while inotifywait -r -e modify,create,delete,move "$PROJECT_DIR"; do echo "Changes detected, syncing..." rsync -avz --delete \ --exclude '.git' \ --exclude 'node_modules' \ "$PROJECT_DIR/" "$WORKSPACE"doneUsing WSL (Windows)
Section titled “Using WSL (Windows)”For Windows users, we recommend using Windows Subsystem for Linux (WSL) for the best rsync experience:
# Install WSL (PowerShell as Administrator)wsl --install
# Inside WSL, install rsyncsudo apt-get updatesudo apt-get install rsync
# Use the same Linux scripts above# Access Windows files via /mnt/c/Users/YourName/projectYou can then use the inotifywait script above, adjusting paths to access your Windows files:
#!/bin/bashPROJECT_DIR="/mnt/c/Users/YourName/project"WORKSPACE="wsm.my_workspace:~/project/"
while inotifywait -r -e modify,create,delete,move "$PROJECT_DIR"; do echo "Changes detected, syncing..." rsync -avz --delete \ --exclude '.git' \ --exclude 'node_modules' \ "$PROJECT_DIR/" "$WORKSPACE"doneBidirectional Sync with Unison
Section titled “Bidirectional Sync with Unison”For true two-way synchronization, consider using Unison:
# Install Unisonbrew install unison # macOSsudo apt-get install unison # Ubuntu/Debian
# Create sync profileunison ~/local/project ssh://wsm.my_workspace//home/web/project \ -ignore 'Name .git' \ -ignore 'Name node_modules' \ -auto -batchExcluding Files
Section titled “Excluding Files”Using —exclude Flags
Section titled “Using —exclude Flags”Exclude specific files or directories:
rsync -avz \ --exclude '.git' \ --exclude 'node_modules' \ --exclude '*.log' \ --exclude '.env' \ ~/local/project/ wsm.my_workspace:~/project/Using —exclude-from File
Section titled “Using —exclude-from File”Create an exclude file (similar to .gitignore):
.gitnode_modules*.log.env.DS_Storedist/build/*.pyc__pycache__/Use it with rsync:
rsync -avz --exclude-from='.rsyncignore' \ ~/local/project/ wsm.my_workspace:~/project/Using Existing .gitignore
Section titled “Using Existing .gitignore”You can leverage your existing .gitignore:
rsync -avz \ --filter=':- .gitignore' \ ~/local/project/ wsm.my_workspace:~/project/Performance Optimization
Section titled “Performance Optimization”Use Compression Wisely
Section titled “Use Compression Wisely”For fast networks, compression overhead may slow things down:
# Skip compression on fast networksrsync -av ~/local/project/ wsm.my_workspace:~/project/Limit Bandwidth
Section titled “Limit Bandwidth”Prevent rsync from saturating your connection:
# Limit to 1000 KB/srsync -avz --bwlimit=1000 \ ~/local/project/ wsm.my_workspace:~/project/Incremental Transfers
Section titled “Incremental Transfers”rsync is already incremental by default, but you can optimize further:
# Use checksum instead of timestamp for change detectionrsync -avzc ~/local/project/ wsm.my_workspace:~/project/Parallel Transfers
Section titled “Parallel Transfers”For many small files, consider using parallel rsync:
# Install parallelbrew install parallel # macOSsudo apt-get install parallel # Ubuntu/Debian
# Parallel syncfind ~/local/project -type f | parallel -j 4 \ rsync -avz {} wsm.my_workspace:~/project/{}Troubleshooting
Section titled “Troubleshooting”Permission Denied
Section titled “Permission Denied”Ensure you have write permissions on the workspace:
# Check permissionsssh wsm.my_workspace "ls -la ~/project"
# Fix permissions if neededssh wsm.my_workspace "chmod -R u+w ~/project"Connection Issues
Section titled “Connection Issues”If rsync fails to connect:
- Verify SSH access works:
ssh wsm.my_workspace - Update SSH config:
wsm-cli ssh config-update - Check workspace is running in WSM admin
Slow Transfers
Section titled “Slow Transfers”If syncing is slow:
- Use
--progressto identify bottlenecks - Exclude large binary files or build artifacts
- Consider using
--compress-level=1for faster compression - Check network connectivity
Files Not Syncing
Section titled “Files Not Syncing”If changes aren’t syncing:
- Verify paths are correct (note trailing slashes matter!)
- Check exclude patterns aren’t too broad
- Use
--dry-runto preview what would sync - Add
-vvfor verbose debugging output
Alternative Tools
Section titled “Alternative Tools”Mutagen
Section titled “Mutagen”Mutagen provides real-time, bidirectional synchronization with better performance for large projects:
# Install Mutagenbrew install mutagen-io/mutagen/mutagen
# Create sync sessionmutagen sync create ~/local/project wsm.my_workspace:~/project \ --ignore=.git --ignore=node_modules
# List sessionsmutagen sync list
# Monitor sessionmutagen sync monitorUnison
Section titled “Unison”Unison offers true bidirectional sync with conflict detection:
unison ~/local/project ssh://wsm.my_workspace//home/web/project \ -ignore 'Name .git' \ -ignore 'Name node_modules'Mount the remote workspace as a local filesystem:
# Install SSHFSbrew install macfuse sshfs # macOSsudo apt-get install sshfs # Ubuntu/Debian
# Mount workspacemkdir ~/workspace-mountsshfs wsm.my_workspace:~/project ~/workspace-mount
# Unmount when doneumount ~/workspace-mountRelated Documentation
Section titled “Related Documentation”- SSH Access - Configure SSH access to workspaces
- Connecting JetBrains IDEs - Use JetBrains remote development
- Connecting Visual Studio Code - Use VS Code Remote-SSH