Incremental Robocopy Backup Batch Script


FreeBooter

Well-known member
Pro User
VIP
Local time
11:10 PM
Posts
3,923
OS
Windows 11
This batch script makes a total copy first using Robocopy command and then incrementally, :: ie, it just copies the new files and changed files.

Batch:
@echo off
:: Incremental_Backup.bat Created by FreeBooter
:: It is a total copy first and then incrementally,
:: ie, it just copies the new files and changed files.
mode con cols=95 lines=5 & color 0E
Title %~nx0 for Incremental Backup with XCopy Command by FreeBooter 2025
set "Settings=%~dp0Settings.ini"
Set "FirstFull_CopyLog=%~dp0%~n0_FirstFull_CopyLog.txt"
Set "LogFile=%~dp0%~n0_Incremental_CopyLog.txt"
If not exist "%Settings%" (
    Call :BrowseForFolder "Please choose the source folder for the backup" SourceFolder
    Setlocal EnableDelayedExpansion
    If defined SourceFolder (
        echo(
        echo             You chose "!SourceFolder!" as source folder
    ) else (
        echo(
        Color 0C & echo                    The source folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )
    Call :BrowseForFolder "Please choose the target folder for the backup" TargetFolder
    If defined TargetFolder (
        echo(
        echo             You chose "!TargetFolder!" as Target folder
    ) else (
        echo(
        Color 0C & echo                    The Target folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )
Timeout /T 3 /nobreak>nul
    (
        echo "!SourceFolder!"
        echo "!TargetFolder!\Backups_%ComputerName%\"
    )
cls & echo( & echo(
echo         Please wait a while ... The Backup to "!TargetFolder!" is in progress...
Call :Backup_XCopy "!SourceFolder!" "!TargetFolder!" "!FirstFull_CopyLog!"
Timeout /T 1 /nobreak>nul
Start "" "!FirstFull_CopyLog!" & exit
) else (
Setlocal EnableDelayedExpansion
for /f "delims=" %%a in ('Type "%Settings%"') do (
    set /a idx+=1
    set Param[!idx!]=%%a
)

Set "SourceFolder=!Param[1]!"
Set "TargetFolder=!Param[2]!"
echo(
echo        The source Folder from Settings.ini is : !SourceFolder!
echo        The Target Folder from Settings.ini is : !TargetFolder!
Timeout /T 1 /nobreak>nul & cls & echo( & echo(
echo       Please wait a while ... The Backup to !TargetFolder! is in progress...
Call :Backup_XCopy !SourceFolder! !TargetFolder! !LogFile!
)
Timeout /T 1 /nobreak>nul
Start "" !LogFile! & exit
::****************************************************************************
:BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b
::****************************************************************************
:Backup_XCopy <Source> <Target> <LogFile>
Robocopy /E /IM /FP %1 %2 > %3 2>&1
Exit /b
::****************************************************************************
 

Attachments

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
I'm using

robocopy C:\Source D:\Destination /E /XC /XN /XO /R:1 /W:1

Where:
/e Copies subdirectories. Note that this option includes empty directories
/xc Excludes changed files.
/xn Excludes newer files.
/xo Excludes older files.


It's easy.
 

My Computer

System One

  • OS
    Windows 7/11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP/Lenovo/Asus
    CPU
    Intel i7-11800H
    Motherboard
    Lenovo Legion 5i Pro Gen 6
    Memory
    32GB DDR4 3200MHz
    Graphics Card(s)
    NVIDIA GeForce RTX 3070
    Hard Drives
    1TB PCIe SSD
I'm using

robocopy C:\Source D:\Destination /E /XC /XN /XO /R:1 /W:1

Where:
/e Copies subdirectories. Note that this option includes empty directories
/xc Excludes changed files.
/xn Excludes newer files.
/xo Excludes older files.


It's easy.
Isn't that command only does full backup, not incremental backup?
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
robocopy is designed for that (incremental backup).
hence would be easy format.

robocopy C:\SourceFolder D:\DestinationFolder


If NOT clear, you can get AI answer
1736491476397.webp
 

My Computer

System One

  • OS
    Windows 7/11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP/Lenovo/Asus
    CPU
    Intel i7-11800H
    Motherboard
    Lenovo Legion 5i Pro Gen 6
    Memory
    32GB DDR4 3200MHz
    Graphics Card(s)
    NVIDIA GeForce RTX 3070
    Hard Drives
    1TB PCIe SSD
Early discussion

 

My Computer

System One

  • OS
    Windows 7/11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP/Lenovo/Asus
    CPU
    Intel i7-11800H
    Motherboard
    Lenovo Legion 5i Pro Gen 6
    Memory
    32GB DDR4 3200MHz
    Graphics Card(s)
    NVIDIA GeForce RTX 3070
    Hard Drives
    1TB PCIe SSD
The /MIR switch can delete files, i don't trust AI it does not test the script result like i did AI just reports best answer.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
I have been using that command.

It's upto you.

I'm using

robocopy C:\Source D:\Destination /E /XC /XN /XO /R:1 /W:1

Where:
/e Copies subdirectories. Note that this option includes empty directories
/xc Excludes changed files.
/xn Excludes newer files.
/xo Excludes older files.


It's easy.
 

My Computer

System One

  • OS
    Windows 7/11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP/Lenovo/Asus
    CPU
    Intel i7-11800H
    Motherboard
    Lenovo Legion 5i Pro Gen 6
    Memory
    32GB DDR4 3200MHz
    Graphics Card(s)
    NVIDIA GeForce RTX 3070
    Hard Drives
    1TB PCIe SSD
My script works way i wanted it does incremental back and full backup so why shall i use AI result for backup already works.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1

Latest Support Threads

Back
Top Bottom