Personal backups using ROBOCOPY
You must already know how to use batch commands to use this page. I accept no responsibility for any accidents you have due to badly written batch commands.
I use commercial backup software to create drive images once a month. For daily changes to personal files, I find it easier to use a batch program to copy modified files. I use a built-in Windows program ROBOCOPY, which is designed for folder backups. Configured properly, it runs very quickly. I put Robocopy commands into a Batch Program, which allows me to customize the commands easily. Best of all, I can run the Batch Program daily using Windows Task Scheduler.
Start by copying the text below into a text editor. Save the file with the .bat extension (i.e. BackupMyFiles.bat). Use the commands and switches that do what you need to do. Edit the source and destination paths to match YOUR system. The commonly used text strings are assigned to variable names so you can more easily write command lines without making mistakes. If you wish, you can add a variable for the destination drive (set dest=H:\BACKUPS\). But be very careful using the mirror commands - a single typo can wipe out data in an instant! Test carefully before you schedule the Batch Program. Use the /L switch on commands for testing. Testing one command at a time and then combining them is the best way to avoid disasters. Testing requires the log file. It lists all file comparisons, even those that do not result in a copy - the reason for sending screen output to a log file!
Batch Program
@echo off
ECHO TEMPLATE to backup some C/D folders to H drive
REM Set Date
for /F "delims=/ " %%i in ('date /t') do (set Date=%%i)
REM Set log location
set log=H:\BACKUPS\Robocopy_Logs\%Date%.log
REM Set command to copy only files with the Archive attribute & reset it.
set APP=C:\Windows\System32\Robocopy.exe
REM Robocopy switches to copy folder tree, log full path
set SW1=/M /E /R:0 /XA:H /MT /NS /NC /XJ /FP /S /LOG+:%log%
REM Robocopy switches to copy folders but not subfolders
set SW2=/M /E /R:0 /XA:H /MT /NS /NC /XJ /LOG+:%log%
REM Robocopy switches to Mirror folder: deletes dest. files not found in source
set MIRROR=/MIR /R:0 /XA:H /MT /NS /NC /XJ /LOG+:%log%
REM Command switches to Mirror Websites, Skipping some filetypes and folders
set MIRRORX=/MIR /R:0 /XA:H /MT /NS /NC /XF *.zip *.bak /XD old Templates /LOG+:%log%
REM Note: all logs for this date are appended
ECHO. >> %LOG%
ECHO. >> %LOG%
ECHO ROBOCOPY.BAT COPY FOLDERS TO DRIVE H %Date% >> %LOG%
ECHO. >> %LOG%
ECHO Backup folders (My Pictures)
ECHO --------------------------------------------
%APP% "C:\Users\Pat\My Pictures" "H:\Users_Pat\My Pictures" %SW2%
ECHO.
ECHO Backup folders, but not subfolders (Tools)
ECHO --------------------------------------------
%APP% D:\Tools H:\Tools %SW1%
ECHO.
ECHO MIRROR folders (User's Desktop, Start Menus)
ECHO --------------------------------------------
%APP% C:\Users\Pat\Desktop "H:\Users_Pat\Desktop" %MIRROR%
%APP1% "C:\Users\Pat\AppData\Roaming\Microsoft\Windows\Start Menu" "H:\Users_Pat\StartMenu-Pat" %MIRROR%
ECHO.
ECHO Done
ECHO. >> %log%
ECHO ================================================ >> %log%
ECHO. >> %log%
ECHO.
EXIT
ROBOCOPY SWITCHES
Open a command prompt (Start > Run > "cmd") and type the following command to view all Robocopy documentation (in pages):
robocopy /? | more
Here are some Robocopy switches with their explanations.
| /E | copy subfolders incl empty ones |
| /FP | Full path in log |
| /L | List only. Don't copy, timestamp or delete files. |
| /LOG+:{file} | Append to log file |
| /M | copy only files with the Archive attribute; reset it. |
| /MIR | Mirror mode, delete destination files not present in source |
| /MT[:n] | multi-threaded copies with n threads (default 8). |
| /NC | don't log file classes. |
| /NDL | No directory list – do not log directory names. |
| /NFL | No file list – don't log file names. |
| /NP | No progress – don't display % copied. |
| /NS | don't log file sizes |
| /PURGE | Deletes files no longer in the source location. |
| /R:0 | zero Retries on failed copies |
| /S | copy subfolders but not empty ones |
| /V | Produce verbose output, showing skipped files. |
| /X | Report all extra files, not just those selected. |
| /XA:H | Do not copy HIDDEN files |
| /XD dirspec | Excludes folders. (BAK* skips folders starting with "BAK" |
| /XJ | Don't follow junctions |
To learn more about Batch Programs, open the Windows Help System (Start > Help or F1 key) and type this: What is batch command. Select any items about command prompt.
Hint: If your Start Menu does not contain a Run command, right click on the taskbar (bottom of screen) and select Properties. Click the Start Menu tab, then Customize. Select the item to display the Run command.
|