This tool provides an automated way to synchronize projects between your WSL (Windows Subsystem for Linux) environment and Windows file system. It's particularly useful for backing up your WSL projects to Windows or for accessing your WSL files through Windows applications.
The synchronization tool uses rsync to efficiently copy files from a source directory (typically in WSL) to a destination directory (typically in Windows), while respecting exclusion patterns for files and directories you don't want to sync.
- One-way synchronization from WSL to Windows
- Configurable source and destination directories
- Customizable file/directory exclusion patterns
- Optional automated syncing via cron jobs
- Logging of sync operations
- WSL installed on Windows
rsyncinstalled in your WSL distribution- Basic knowledge of bash scripting
-
Create the configuration file:
touch ~/.syncservice.conf -
Save the
sync_projects.shscript to a location of your choice (e.g.,~/scripts/sync_projects.sh) -
Make the script executable:
chmod +x ~/scripts/sync_projects.sh
Edit the ~/.syncservice.conf file with your preferred text editor:
nano ~/.syncservice.confAdd the following content, adjusting paths and exclusion patterns to your needs:
# Sync configuration
SOURCE_DIR="/home/your-username/projects"
DEST_DIR="/mnt/c/Users/your-windows-username/Documents/projects"
# Exclude patterns (matching any folder name or path)
EXCLUDE_PATTERNS=(
"node_modules"
".git"
"venv"
"*.log"
"*.tmp"
# Add any other directories or file patterns you want to exclude
)SOURCE_DIR: The WSL directory containing your projectsDEST_DIR: The Windows directory where files will be synchronized toEXCLUDE_PATTERNS: An array of file patterns or directory names to exclude from synchronization
To run a sync operation manually:
~/scripts/sync_projects.sh --syncWhen you run the script without the --sync flag in an interactive terminal, it will offer to set up automated synchronization via cron:
~/scripts/sync_projects.shFollow the prompts to select your preferred sync frequency:
- Every hour
- Every 2 hours
- Every 6 hours
- Daily
- Custom cron schedule
- Cancel
The script will add an appropriate cron job to run synchronization automatically.
To run the sync operation without interactive prompts (e.g., from another script):
~/scripts/sync_projects.sh --syncSync operations are logged to ~/sync.log when run via cron. You can check this file to verify that syncs are occurring as expected:
tail -f ~/sync.logThe default configuration excludes common directories and files you typically don't want to synchronize, such as:
- Node.js modules (
node_modules) - Git repositories (
.git) - Python virtual environments (
venv,.venv,myenv) - Log files (
*.log) - Temporary files (
*.tmp)
You can customize these exclusions in the ~/.syncservice.conf file.
If synchronization fails, check:
- That both source and destination directories exist
- That you have appropriate permissions
- That there's enough disk space in the destination
- The sync log file for specific error messages
If the automated sync isn't running:
- Check if the cron job was installed correctly:
crontab -l
- Verify that the cron service is running:
service cron status
- Check the log file for errors:
cat ~/sync.log
- The script preserves file content but does not preserve ownership or group information
- Consider the security implications of syncing sensitive files to Windows
- This is a one-way sync from WSL to Windows
- Large repositories with many files may take time to sync initially
- Windows file system limitations may affect certain Linux files
To remove the automated sync:
crontab -l | grep -v "SYNC_PROJECTS_CRON" | crontab -To completely remove the tool, also delete:
- The script file
- The configuration file (
~/.syncservice.conf) - The log file (
~/sync.log)