Incremential Backup with 7Zip

The following tutorial describes how a simple incremential backup mechanism can be implemented with 7Zip.

Status: This is not working on Win10 and the current 7Zip version installed on the dev computers.

7Zip Backup SendTo Menu

7Zip Backup SendTo Menu

All credits go to…

Inkrementelle Backups mit 7zip

For… Full Backup, Diff, Restore and Backup Bat: visit his site.


@echo off

REM === HIER ANPASSEN : ============================================================
REM Pfad zu 7zip
set Z=C:\Program Files\7-Zip\7z.exe
REM Standard Backup Ordner
set BF=d:\Backup

REM ============ VERARBEITUNG ======================================================
set SF=%1%
REM Hochkomma weg
set SF=%SF:"=%

REM Filename
for /f "tokens=* delims= " %%f in ("%SF%") do set SN=%%~NXf

REM Alternativ Pfad bauen
set SP=%SF:\\=NET\%
set SP=%SP::=%
set SP=%SP:"=%

REM EXCLUDE LIST
rem -xr!*.o
set xcl=
:loop
shift
if "%1"=="" goto :endloop
set xcl=%xcl% -xr!%1%
goto :loop
:endloop
cls
echo EXCLUDES: %xcl%

Echo BACKUP : %d%%t% von %SF%
echo PFAD : %BF%\%SP%\%d%%t%.7z
echo EXCLUDES: %xcl%
echo.
echo.

REM 7Z
if exist "%BF%\%SP%\basis.7z" goto :increment
Rem Backup
"%Z%" a "%BF%\%SP%\basis.7z" "%SF%" %xcl%
goto :end

:increment
REM DATETIME
for /f "tokens=1,2,3,4 delims=. " %%i in ('date /t') do set d=%%k-%%j-%%i
for /f "tokens=1,2 delims=: " %%i in ('time /t') do set t=%%i%%j
set inc=%BF%\%SP%\%d%%t%.7z

REM Backup Incrementell
"%Z%" u "%BF%\%SP%\basis.7z" "%SF%" -ms=off -mx=9 -t7z -u- -up0q3r2x2y2z0w2!"%inc%" %xcl%

:end

explorer.exe "%BF%\%SP%"

This Script has to be placed in:
C:\Users\[YourUser]\AppData\Roaming\Microsoft\Windows\SendTo
FileName:
bgp_7zbackup_script.bat

Usage:
Rightclick a folder you want to backup – choose the FileName from the “SendTo” menu entry.

Leave a Reply