A powerful Windows batch script that automates backup operations across multiple network devices. This script creates timestamped backups, compresses them automatically, and provides comprehensive logging for enterprise and home network environments.
- Multi-Device Support: Backup from up to 4+ network devices simultaneously
- Automatic Compression: Creates ZIP archives to save storage space
- Comprehensive Logging: Detailed logs with timestamps for audit trails
- Network Connectivity Check: Pings devices before attempting backup
- Error Handling: Robust error detection and reporting
- Administrative Share Support: Uses Windows admin shares (C$, D$, E$)
- Customizable Paths: Easy configuration for different network topologies
- Space Optimization: Automatic cleanup of uncompressed folders after archiving
- Windows 10/11 or Windows Server 2016+
- PowerShell 5.0+ (for compression functionality)
- Administrative privileges on the backup source machine
- Network connectivity to target devices
- All target devices must be accessible via network
- Administrative shares must be enabled on target devices
- Appropriate network permissions for file access
- Stable network connection for large file transfers
-
Download the Script
git clone https://github.com/valley4techs/multi-device-network-backup-script.git cd multi-device-network-backup-script -
Configure Target Devices
- Enable administrative shares on target machines
- Ensure Windows File and Printer Sharing is enabled
- Configure appropriate user permissions
-
Test Network Connectivity
ping 192.168.1.1 ping 192.168.1.203 ping 192.168.1.11 ping 192.168.1.80
The script is pre-configured to backup from these devices:
| Device IP | Source Path | Description |
|---|---|---|
| 192.168.1.1 | D:\medlab\medlab | Medical lab data |
| 192.168.1.203 | E:\Work | Work documents |
| 192.168.1.11 | D:\Work | Work files |
| 192.168.1.80 | D:\Work | Additional work data |
To add a new device (e.g., 192.168.1.100 with folder C:\Documents):
- Locate the last backup section in the script
- Add the following code block:
REM ---- Backup 5: Device 192.168.1.100, Folder C:\Documents ----
set "device5_ip=192.168.1.100"
set "source5=\\%device5_ip%\C$\Documents"
set "dest5=%baseBackupDir%\192.168.1.100_C_Documents"
echo.
echo Backing up %source5% to %dest5%
echo -------------------------------------------------- >> "%logFile%"
echo [%timestamp%] Starting backup for %source5% >> "%logFile%"
ping -n 1 %device5_ip% >nul
if errorlevel 1 (
echo [%timestamp%] ERROR: Cannot reach %device5_ip%. Skipping backup for %source5%. >> "%logFile%"
) else (
mkdir "%dest5%"
robocopy "%source5%" "%dest5%" /E
if errorlevel 8 (
echo [%timestamp%] ERROR: Backup for %source5% failed with ROBOCOPY error code %errorlevel%. >> "%logFile%"
) else (
echo [%timestamp%] SUCCESS: Backup for %source5% completed successfully. >> "%logFile%"
)
)Change the backup destination by modifying:
set "localBackupDir=D:\Backup"-
Run as Administrator (Required for network access)
Right-click on backup_script.bat β "Run as administrator" -
Monitor Progress
- Watch console output for real-time status
- Check log files in
D:\Backup\logs\for detailed information
-
Verify Backups
- Compressed backups are stored in
D:\Backup\ - Format:
Backup_YYYY-MM-DD_HH-MM-SS.zip
- Compressed backups are stored in
- Open Windows Task Scheduler
- Create Basic Task
- Set trigger (daily, weekly, etc.)
- Set action to start the batch file
- Configure to run with highest privileges
The script currently runs with default parameters. For custom ROBOCOPY options, modify the robocopy commands in the script.
D:\Backup\
βββ Backup_2024-01-15_14-30-25.zip # Compressed backup archive
βββ Backup_2024-01-16_14-30-25.zip # Daily backups
βββ logs\
βββ backup_log_2024-01-15_14-30-25.txt
βββ backup_log_2024-01-16_14-30-25.txt
[2024-01-15_14:30:25] Starting backup for \\192.168.1.1\D$\medlab\medlab
[2024-01-15_14:31:45] SUCCESS: Backup for \\192.168.1.1\D$\medlab\medlab completed successfully.
[2024-01-15_14:31:46] Starting compression of D:\Backup\Backup_2024-01-15_14-30-25
[2024-01-15_14:35:12] SUCCESS: Compression completed successfully.
Cause: Network connectivity issues Solution:
- Verify IP addresses are correct
- Check network cables and switches
- Ensure target devices are powered on
Cause: Insufficient permissions Solution:
- Run script as Administrator
- Verify administrative shares are enabled
- Check user account permissions on target devices
Cause: File access or disk space issues Solution:
- Check available disk space on backup drive
- Verify source paths exist and are accessible
- Review file permissions on source directories
Cause: PowerShell or disk space issues Solution:
- Ensure PowerShell 5.0+ is installed
- Check available disk space
- Verify PowerShell execution policy allows script execution
Add these ROBOCOPY parameters for better performance:
robocopy "%source%" "%dest%" /E /R:3 /W:10 /MT:8/R:3- Retry 3 times on failed copies/W:10- Wait 10 seconds between retries/MT:8- Use 8 parallel threads
robocopy "%source%" "%dest%" /E /R:5 /W:30 /TBD/R:5- More retries for unstable networks/W:30- Longer wait between retries/TBD- Wait for share names to be defined
π₯ Watch the complete setup and usage guide: YouTube Tutorial Link
The video covers:
- Step-by-step installation
- Adding new devices
- Troubleshooting common issues
- Best practices for network backups
Contributions are welcome! Please feel free to submit a Pull Request.
- Test all changes on a virtual network environment
- Update documentation for any new features
- Maintain backward compatibility when possible
- Add appropriate error handling for new functionality
Please use the GitHub Issues tab to report:
- Bugs or unexpected behavior
- Feature requests
- Documentation improvements
- Performance issues
This project is licensed under the MIT License - see the LICENSE file for details.
Valley4Techs
- YouTube: Valley4Techs
- GitHub: Valley4Techs
- Thanks to the Windows ROBOCOPY team for the robust file copying utility
- Community feedback and contributions
- All users who provided testing and feedback
- Initial release
- Support for 4 network devices
- Automatic compression and logging
- Basic error handling and connectivity checks
β If this script helped you, please consider giving it a star! β