Handy USB backup script
Categories:

Here's a handy backup batch script, useful for keeping backups of USB flash drives. It will save the backup files in C:\User\[username]\[backupdir], with backupdir using the same name as the batch file. This makes it easy to have multiple backups from different USB drives, as only the batch file name needs to change to save the backup to a different folder. (This also means that the file MUST be named differently for different drives as to avoid clobbering another backup)

I suggest naming the file something like "Backup-Kingston4gb.bat"

@echo off

echo --== Backup USB files to local computer ==--
echo.

:: Sets the backupname to the name of the batch file (less path and extension)
set BACKUPNAME=%~n0
set DEST=%HOMEDRIVE%%HOMEPATH%\%BACKUPNAME%

if not exist "%DEST%" (
mkdir "%DEST%"
if ERRORLEVEL 1 (
echo.
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo ! There was a problem creating the  !
echo ! backup directory on the local     !
echo ! computer:                         !
echo ! %DEST%
echo ! Backup cannot continue until this !
echo ! is fixed.                         !
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo.

pause
goto end
)
echo Created backup directory "%DEST%"
)

echo Starting backup to "%DEST%"
echo.

robocopy .\ "%DEST%" /MIR /XJ /R:2 /W:5

echo.
echo.
echo Files have been saved in "%DEST%"
echo.

pause
:end