Winrar Monthly Backup Script

I use this script to backup websites and data each month it takes a list of paths and uses winrar via command line appending the current month day year.

@echo off
setlocal enabledelayedexpansion

:: Define the list of folders to archive
set "folders=C:\path\site1 C:\path\site2 C:\path\site3"

:: Get current date components
for /f "tokens=2 delims==" %%I in ('wmic OS Get localdatetime /value') do set datetime=%%I
set "year=!datetime:~0,4!"
set "month=!datetime:~4,2!"
set "day=!datetime:~6,2!"

:: Define WinRAR path (update accordingly)
set "winrar_path=C:\Program Files\WinRAR\WinRAR.exe"

:: Iterate over folders and create archives
for %%F in (%folders%) do (
    for %%A in ("%%F") do set "folder_name=%%~nA"
    set "rar_name=!folder_name!_files_!month!!day!!year!.rar"

    echo Archiving "%%F" as "!rar_name!" with 50GB splits...
    "%winrar_path%" a -r -v50g "!rar_name!" "%%F"
)

echo All archives created successfully with 50GB splits.
endlocal
pause

Leave a Reply