|
Answer» I am pretty NEW to batch scripting. I would like to make a batch file to backup certain directories, to another location. Also, i would like to CREATE an output log with the details of the backup and whether it was successful or not. Finally, i would like this log to have a time stamp (begin and end, if possible a time stamp for each line entry. Below is what i have so far. THANK you.
@echo off Q: :Make mkdir Logs IF EXIST Logs GOTO LOG CD\Logs IF EXIST Logs\BackupLog.txt GOTO LOG
:CREATE ECHO BACKUP LOG > Logs\BackupLog.txt ECHO. >> Logs\BackupLog.txt
:CREATE ECHO BACKUP LOG > Logs\BackupLog.txt ECHO. >> Logs\BackupLog.txt
:LOG ECHO File Backup has started: >> \Logs\BackupLog.txt ECHO. |DATE| FIND "Current" >> \Logs\BackupLog.txt ECHO. |TIME| FIND "Current" >> \Logs\BackupLog.txt
ECHO. >> Logs\BackupLog.txt ECHO File Backup was stopped: >> \Logs\BackupLog.txt ECHO. |DATE| FIND "Current" >> \Logs\BackupLog.txt ECHO. |TIME| FIND "Current" >> \Logs\BackupLog.txt ECHO --------------------- >> \Logs\BackupLog.txt ECHO. >> \Logs\BackupLog.txt
mkdir Batches IF EXIST Batches GOTO Backup mkdir Rules IF EXIST Rules GOTO Backup mkdir Signatures IF EXIST Signature GOTO Backup mkdir Templates IF EXIST Templates GOTO Backup :Backup ECHO BACKUP IN PROGRESS xcopy "C:\Documents and Settings\paduanoj\Desktop\Batches" "Q:\Batches" /s /e /k /i xcopy "C:\Documents and Settings\paduanoj\My Documents\Outlook\Backup.Outlook\Rules"
"Q:\Rules" /s /e /k /i xcopy "C:\Documents and Settings\paduanoj\My Documents\Outlook\Templates" "Q:\Templates" /s
/e /k /i xcopy "C:\Documents and Settings\paduanoj\My Documents\Signatures" "Q:\Signatures" /s /e /k
/i
IF ERRORLEVEL 1 GOTO end_on_error
goto end
:end_on_error @echo off ECHO Error During Backup pause
goto end
:endHi There,
all the features, that you NEED can be acomplished by USING robocopy.exe .
You can google on it, I think, you can download it from Microsoft.
It does excellent logging (if you want it), time stamp of starting, ending, time it took to run it, etc.
Check it out, you will be amazed how powerfull this XP/Win2000/W2k3 Command line utility tool, that happens to be a 32 bit executable, so it is also super fast.
Geza
thank you. I will check it out. Although my main goal was to get experience with creating batch files. Thank you again.
|