How to compress a file using WinRAR and make it downloadable on Windows?

Below is the process to convert any file(database file, image file etc.) into WinRAR and make it downloadable using browser: -

backup.bat
==========
@echo off

rem *******************************************************************
rem
rem Set environment variables with date/time information.
rem
rem DT_MONTH .................... Two digit month
rem DT_DAY ...................... Two digit day
rem DT_YEAR ..................... Four digit year
rem DT_HOUR ..................... Two digit hour
rem DT_MINUTE ................... Two digit minute
rem DT_SECOND ................... Two digit second
rem DT_RFC ...................... YYYYMMDDTHHMMSS
rem
rem *******************************************************************

rem Grab date and time values for conversion.

SET _CUR_DATE=%DATE%
SET _CUR_TIME=%TIME%



FOR /F "tokens=1-4 delims=/.- " %%a IN ("%_CUR_DATE%") DO SET DT_MONTH=%%b
FOR /F "tokens=1-4 delims=/.- " %%a IN ("%_CUR_DATE%") DO SET DT_DAY=%%c
FOR /F "tokens=1-4 delims=/.- " %%a IN ("%_CUR_DATE%") DO SET DT_YEAR=%%d

rem Convert from "11:40:12.82" to individual parts by using a DOS FOR loop.

FOR /F "tokens=1-4 delims=:." %%a IN ("%_CUR_TIME%") DO SET DT_HOUR=%%a
FOR /F "tokens=1-4 delims=:." %%a IN ("%_CUR_TIME%") DO SET DT_MINUTE=%%b
FOR /F "tokens=1-4 delims=:." %%a IN ("%_CUR_TIME%") DO SET DT_SECOND=%%c

SET DT_RFC=%YEAR%%MONTH%%DAY%T%HOUR%%MINUTE%%SECOND%


rar.bat
======

@echo off

rem Get date/time values
call D:\\Backup-scripts\\backup.bat
SET YEAR=%DT_YEAR%
SET MONTH=%DT_MONTH%
SET DAY=%DT_DAY%
SET HOUR=%DT_HOUR%
SET MINUTE=%DT_MINUTE%
SET SECOND=%DT_SECOND%


"C:\\Program Files\\Winrar\\rar.EXE" a -r D:\\wamp\\www\\riphahtechcom\\downloads\\moodle\\%MONTH%-%DAY%-%YEAR%.rar D:\\wamp\\www\\database\\moodle-backup-%YEAR%%MONTH%%DAY%.sql

In this example, rar.exe should be present in the path C:\Program Files\Winrar\rar.EXE
Put it rar.bat in Windows schedular to make it a cron job(activates automatically on the set date and time).

Nice one, I have not seen a bat file in ages. :slight_smile:

That’s pretty interesting, ta!