1) Decide where you want to keep your backups and create a directory.
2) Create a file called "USBbackup.cmd"
3) Edit the file using Notepad, copying the following text into the file.
@echo off
title USB BackUp
cd /d %~dp0
set /p BACKUPDIR="Enter drive letter to be backed up..: "
REM ====
REM Check if backup source is drive or directory
if exist "%BACKUPDIR%:\." ( set BACKUPDIR=%BACKUPDIR%:
) else ( if not exist %BACKUPDIR%\. goto :error )
REM ====
REM Create sub directory based on date.
for /f "tokens=1,2,3 delims=/" %%A in ('echo %DATE%') do set TARGET=Backup-%%C%%B%%A
for /f "tokens=1,2,3 delims=:." %%A in ('echo %TIME%') do set TARGET=%TARGET%-%%A%%B%%C
REM ====
REM Check source and target
echo Backing up from drive "%BACKUPDIR%" to "%TARGET%"
pause
REM ====
REM Create target directory and backup files
title Backing up files
if not exist ".\%TARGET%\." mkdir .\%TARGET%
XCOPY /E "%BACKUPDIR%\*.*" ".\%TARGET%\"
REM ====
REM Finalise
title Usb Backup Complete
goto :end
:error
title Usb Backup Error
echo Unable to locate drive "%BACKUPDIR%"
:end
pause
title USB BackUp
cd /d %~dp0
set /p BACKUPDIR="Enter drive letter to be backed up..: "
REM ====
REM Check if backup source is drive or directory
if exist "%BACKUPDIR%:\." ( set BACKUPDIR=%BACKUPDIR%:
) else ( if not exist %BACKUPDIR%\. goto :error )
REM ====
REM Create sub directory based on date.
for /f "tokens=1,2,3 delims=/" %%A in ('echo %DATE%') do set TARGET=Backup-%%C%%B%%A
for /f "tokens=1,2,3 delims=:." %%A in ('echo %TIME%') do set TARGET=%TARGET%-%%A%%B%%C
REM ====
REM Check source and target
echo Backing up from drive "%BACKUPDIR%" to "%TARGET%"
pause
REM ====
REM Create target directory and backup files
title Backing up files
if not exist ".\%TARGET%\." mkdir .\%TARGET%
XCOPY /E "%BACKUPDIR%\*.*" ".\%TARGET%\"
REM ====
REM Finalise
title Usb Backup Complete
goto :end
:error
title Usb Backup Error
echo Unable to locate drive "%BACKUPDIR%"
:end
pause
4) Save the file and run it by double clicking on it.
5) When prompt, enter the drive letter or directory to be backed up.
USB Stick backup... Done.
No comments:
Post a Comment