Backup solution with WinRAR and a batch file

By Ryan
Picture of the author
Published on

2024 update: Don't do this. Use Duplicacy.

I wanted to make the perfect manual backup solution in a batch file, so here's the code. Just make a file called backup.bat and paste this text into it. You might have to change a few of the file paths and stuff though.

What it does:

  • Offers to make an exact copy of what files exist now, or lets you continue and add new files that aren't in the backup archive yet (assuming it's you've ran it before)
  • Lets you pick a file name once at the top rather than having to type it in multiple places.
  • Uses a password protected archive.
  • Will make another copy the backup file to another location by default for added safety.

Note: I think I had to make a %path% variable (or whatever those are called) to the WinRAR folder, and I don't exactly remember what I did. It was really easy though.


@ECHO off
SET varFileName=EnterFilenameHere

cls
:start
ECHO *********************************************************
ECHO *         Start a fresh backup? Press Y or N.           *
ECHO *                                                       *
ECHO *      You should do this every once and a while,       *
ECHO *                but not all the time.                  *
ECHO *********************************************************
ECHO.
set choice=
set /p choice=Choice:
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='y' goto yes
if '%choice%'=='n' goto no
ECHO "%choice%" is not valid please try again
ECHO.
goto start

:yes
ECHO ******************** Fresh Backup ***********************
ECHO.
DEL D:Backup"%varFileName%".rar
goto end

:no
ECHO *********************** Update **************************
goto end

:end
ECHO.
ECHO                Cougar Design Backup Wizard
ECHO.
ECHO *********************************************************
ECHO *                                                       *
ECHO *        Choose your password for the archive.          *
ECHO *                                                       *
ECHO *********************************************************
ECHO.
rar a -u -r -rr10 -rv20 -s -hp -m1 D:Backup"%varFileName%".rar @C:Backup"%varFileName%".lst
ECHO.
ECHO *********************************************************
ECHO *              Time to make a 2nd backup!               *
ECHO *********************************************************
ECHO.
xcopy D:Backup"%varFileName%".rar E:Backup"%varFileName%".rar /y /i
ECHO.
ECHO *********************************************************
ECHO *                       Complete!                       *
ECHO *        This will close when you press any key.        *
ECHO *********************************************************
ECHO.
PAUSE