nicoorfi
1/1/2019 - 12:55 PM

Windows make backup from a folder

Make a backup zip from the given folder with 7zip and delete files older than 7 days.

REM This is a batch script to zip files in folder or add /d to zip folders.
REM This script is using 7z to zip files, installation is required - "[http://www.7-zip.org/a/7z938-x64.msi][1]"
REM Remember to point 'do' to 7z installed path 7z.exe

FOR /F %%A IN ('WMIC OS GET LocalDateTime ^| FINDSTR \.') DO @SET B=%%A

SET input1=C:\Program files\Data1\*
SET output1=C:\ZipBackups\%B:~0,4%-%B:~4,2%-%B:~6,2%

REM Make a zip with password 'test1'
"C:\Program Files\7-Zip\7z.exe" a "%output1%.zip" "-ptest1" "-r" "%input1%"

REM Delete files older than 7 days
FORFILES /P "C:\ZipBackups" /M *.* /D -8 /C "cmd /c del @file"