I found out how to backup individual partitions with DISM. It took eleven minutes to back up my C:\ drive of 45 GB.
DISM /Capture-Image /ImageFile:F:\WindowsImage.wim /CaptureDir:C:\ /Name:"Windows Image"
To backup the EFI partition you need to assign it a drive letter. I assigned S to mine using diskpart in an elevate PowerShell Window. You could also use an elevated command prompt.
I then asked ChatGPT to write a batch file to image my S, C and D drives and to error check each stage.
@echo off
setlocal
:: Define backup directory on F: drive
set backup_dir=F:\Backups
:: Create backup directory if it doesn't exist
if not exist "%backup_dir%" mkdir "%backup_dir%"
:: Log file to capture output and errors
set log_file=%backup_dir%\backup_log.txt
echo Backup started at %date% %time% > "%log_file%"
:: Function to check for errors after each command
:check_error
if %errorlevel% neq 0 (
echo Error encountered. Exiting... >> "%log_file%"
exit /b %errorlevel%
)
:: ----------------------------
:: Backup EFI Partition (S:)
:: ----------------------------
echo Capturing EFI partition (S:)...
echo Capturing EFI partition (S:)... >> "%log_file%"
dism /Capture-Image /ImageFile:%backup_dir%\EFI_Backup.wim /CaptureDir:S:\ /Name:"EFI Backup" /CheckIntegrity
call :check_error
:: ----------------------------
:: Backup Windows Partition (C:)
:: ----------------------------
echo Capturing Windows partition (C:)...
echo Capturing Windows partition (C:)... >> "%log_file%"
dism /Capture-Image /ImageFile:%backup_dir%\Windows_Backup.wim /CaptureDir:C:\ /Name:"Windows Backup" /CheckIntegrity
call :check_error
:: ----------------------------
:: Backup Data Partition (D:)
:: ----------------------------
echo Capturing Data partition (D:)...
echo Capturing Data partition (D:)... >> "%log_file%"
dism /Capture-Image /ImageFile:%backup_dir%\Data_Backup.wim /CaptureDir
:\ /Name:"Data Backup" /CheckIntegrity
call :check_error
:: If everything succeeds
echo Backup completed successfully at %date% %time% >> "%log_file%"
echo All partitions have been successfully captured.
exit /b 0
:end
echo Backup failed. Check the log file for details: %log_file%
exit /b 1