RoboCopy Advanced Usage: Job Files and Real-Time Monitoring with /MON and /MOT Switches


2 views

The /JOB and /SAVE switches in RoboCopy enable powerful automation through 'job files' - configuration files that store your copy parameters for repeated execution. A job file is simply a text file containing all the RoboCopy switches you'd normally type on the command line.

# Creating a backup job
RoboCopy C:\Source D:\Backup /MIR /ZB /R:3 /W:5 /LOG+:backup.log /SAVE:DailyBackupJob

# Executing a saved job
RoboCopy /JOB:DailyBackupJob

These switches are particularly useful when working with job files:

  • /NOSD: Indicates no source directory is specified in the command line (must be defined in job file)
  • /NODD: Indicates no destination directory is specified in the command line (must be defined in job file)

The monitoring switches create persistent copy operations that automatically restart when changes occur:

# Example 1: Monitor for 5 changes then restart
RoboCopy C:\WebContent \\Server\Backup /MIR /MON:5

# Example 2: Check every 30 minutes for changes
RoboCopy C:\Database \\NAS\DB_Backup /MIR /MOT:30

Key monitoring behavior:

  • Initial full copy occurs immediately
  • For /MON: RoboCopy counts file changes (creates, modifies, deletes)
  • For /MOT: RoboCopy checks for changes at the specified interval
  • The process remains running in the background between executions

Here's a complete solution for website content synchronization:

# Save the job configuration
RoboCopy C:\Websites\Live \\BackupServer\WebMirror /E /ZB /MT:16 /R:1 /W:1 /TEE /LOG+:WebSync.log /SAVE:WebSyncJob /NODD

# Create a scheduled task that runs:
RoboCopy /JOB:WebSyncJob /MON:1 /MOT:15

This configuration will:

  1. Perform initial full synchronization
  2. Restart after any single file change (from /MON:1)
  3. Also check every 15 minutes for changes (from /MOT:15)
  4. Continue running indefinitely until manually stopped
  • Monitoring processes remain active - use Task Manager to stop them
  • Combine with /LOG for change tracking
  • For high-change environments, set higher /MON values to prevent constant restarts
  • Use /TEE to see real-time output in console while logging

RoboCopy's /MON and /MOT switches provide powerful file monitoring functionality for automated synchronization tasks. Let's break down exactly how they work:


ROBOCOPY source destination /MON:5 /MOT:10

The command above demonstrates combined usage where:

  • /MON:5 will trigger another copy when it detects 5 or more changes
  • /MOT:10 will run again every 10 minutes if changes are detected

Job files (/JOB and /SAVE) allow you to store and reuse complex RoboCopy configurations:


:: Save configuration to job file
ROBOCOPY C:\source D:\backup /MIR /Z /SAVE:backup_job

:: Later execute with saved settings
ROBOCOPY /JOB:backup_job

These switches are particularly useful when working with job files:


:: Create job without specifying directories
ROBOCOPY /NOSD /NODD /MIR /Z /R:3 /W:5 /SAVE:template_job

:: Apply template to different paths
ROBOCOPY C:\data1 D:\backup1 /JOB:template_job
ROBOCOPY C:\data2 D:\backup2 /JOB:template_job

Here's a complete monitoring solution that runs continuously:


@echo off
:loop
ROBOCOPY C:\Projects D:\Backup\Projects /MIR /MON:3 /MOT:30 /LOG+:C:\logs\backup.log
if %ERRORLEVEL% LEQ 3 goto loop
echo Severe error occurred - terminating backup

This script will:

  • Perform initial mirror copy
  • Continue running in background
  • Re-copy after 3 changes or every 30 minutes
  • Log all activity with append mode
  • Handle error conditions appropriately