I’m writing my own batch script to backup some files to an external. here’s what I’ve got so far:
@echo off
:: variables
set /p dname=Enter the Backup drive's drive letter:
set drive=%dname%:\Backup
set folder=%%date:~4,2%_%date:~7,2_date:~10,4%%
set backupcmd=xcopy /s /c /d /e /h /i /r /y /q
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\Documents" "%drive%\Last\Documents"
echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\Last\Favorites"
echo ### Setting backup folder of today's date...
%backupcmd% "%drive%\Last\Documents" "%drive%\%folder%\Documents"
%backupcmd% "%drive%\Last\Favorites" "%drive%\%folder%\Favorites"
echo Backup Complete!
So in the end two folders: Last and today’s date will contain the same thing. I want the Last folder to contain exactly what’s in my C drive currently, however I don’t want to remove the functionality of xcopy only copying newly modified files. Is there a way to recurse through my Documents folder and delete from Last any files that don’t exist in C:?
In other words, first run of the script creates
Last\Documents\file1.txt and (Date)\Documents\file1.txt
the second run (where file1.txt has been removed from drive C:) happens tomorrow and contains:
Last\Documents\(no file1.txt) and (NewDate)\Documents\(no file1.txt)
but
(Date)\Documents\file1.txt
remains intact
I’d suggest looking at the mirror options available in robocopy. Robocopy comes by default in Windows 7 now. It is a great way to go.