Batch file help to backup files+date stamp

February 17, 2012 at 16:29:12
Specs: Windows 7
I'm trying to write a batch file that will backup selected folders when ran, date-stamp the backup folders, but subsequently only cc over new files that need to be backed up. This is what i wrote initially, but now when I run this it creates the date stamped backup folder first, then - seeing that nothing is there - does a complete backup again:

@echo off
:: variables
set drive=C:\Backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y

echo ### Backing up My Documents..
%backupcmd% "%USERPROFILE%\Documents" "%drive%\%folder%\My Documents"
set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%


echo ### Backing up Favorites...
%backupcmd% "%USERPROFILE%\Favorites" "%drive%\%folder%\Favorites"
set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%


echo ### Backing up Desktop...
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\%folder%\Desktop"
set hour=%time:~0,2%
if "%hour:~0,1%"==" " set hour=0%time:~1,1%
set folder=%date:~10,4%_%date:~4,2%_%date:~7,2%_%hour%_%time:~3,2%


:: use below syntax to backup other directories...
:: %backupcmd% "...source directory..." "%drive%\...destination dir..."

echo Backup Complete!
@pause

What should I change to do one initial full backup (first time ran), but subsequently only backup files that have changed in reference to the initial backup, while date stamping.

Thanks,
A


See More: Batch file help to backup files+date stamp

Report •

#1
February 18, 2012 at 22:16:58
Use robocopy it allows you to copy time/date stamps along with many other options.

Its a far better way to copy than just xcopy. It will utilize multi thread processing if in windows 7.

But just type robocopy /? in the cmd and it will tell you all you need to know the string i usually use is this

robocopy "%source%" "%destination%" /E /ZB /DCOPY:T /A-:RASHCNET /COPY:DT /R:2 /W:1 /MT:4 /XJ /FP /ETA /log+:C:\log.txt /TEE


Report •

#2
February 20, 2012 at 06:14:17
Thanks for the input.

I wrote a batch file using robocopy and it's working fine for me, but I have admin rights. When I tested it w/ a normal user they could not run it (they have full read/write/execute rights on both the home and destination folders, but not backup/local admin rights)

Is there a switch a I can write in or use to run this w/o admin rights? Just seeing what the options are, b/c plugging the local admin username/password into the batch script and/or changing user's accounts rights across the domain is not an option.


Report •
Related Solutions


Ask Question