VBS Skripta

poruka: 1
|
čitano: 3.646
|
moderatori: Lazarus Long, XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
17 godina
neaktivan
offline
VBS Skripta

Treba mi skripta koja bi brisala stari backup napravila txt log i poslala izvjesce preko maila. POsto ja nemam pojma kako se to radi imam par samplova , ali ne znam sto treba izbrisati . Skuzio sam da mail salju preko programa blat. Pokusavao sam ja izbrisati i nesto svoje napraviti , ali je to jadno uspjelo posto nisam programer i prvi put se susrecem sa time.

Ovo je skripta koju sam nasao. Samo sto ona radi backup na kazetu.

 

Script 1. the backup script BACKUP.CMD

@echo off
REM #### Set user specific variables
REM
rem if not exist "config.cmd" goto noconfig
call config.cmd
set ConsultantSMTPServer=%SMTPRelayServer%
set LogReportSMTPServer=%SMTPRelayServer%

REM #### Check parameters on the command-line (a little)
REM
if "%1"=="" goto usage
if "%1"=="/?" goto usage
if "%1"=="-h" goto usage
goto done

ECHO #### Check parameters on the command-line (a little more)
REM
:done
if "%1"=="emaillog" goto emaillog
if "%2"=="main" goto main

 

:main
net stop ntmssvc
net start ntmssvc
REM sleep 60
rsm.exe refresh /LF"%TapeDriveName%"
sleep 60
echo i'm here now ready to set media
echo tape drive type===========tapedrive guid
echo tapedrive GUID %tapedriveGUID%
  set media=
  for /f "Tokens=*" %%a in ('rsm view /cg%TapeDriveGUID% /TPhysical_media') do (if not "%%a"=="The command completed successfully." set media=%%a)
  echo %media% ...:%%a
  REM if /i "%media%" EQU "Unable to open session with the RSM server."
  REM echo going to norsm
  REM goto norsm
  REM if /i "%media%" EQU "PHYSICAL_MEDIA"
  REM echo going to notape
  REM goto notape
  REM if not defined media goto notape
  REM if %1==checktape
  REM echo going to end
  REM goto end

ECHO #### Calculate the date and time for the tape name
REM
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i-%%j-%%k-%%l
for /f "Tokens=1" %%i in ('time /t') do set tm=-%%i
set tm=%tm::=-%
echo The time is %tm%

set dtt=%dt%%tm%
echo The Date is %dtt%
REM
ECHO #### Change the name of the tape to today's name (necessary even with /um because
ECHO #### name is used to eject tape at end and name needs to be in ntbackup command too)
REM
  rsm.exe rename /TPhysical_Media /f"%media%" /n"%1 %dtt%"
  Echo Renaming Media
Echo ..
rsm.exe refresh /LF"%TapeDriveName%"
Echo Refreashing tape drive
  sleep 60
  net stop ntmssvc
echo Restarting service
Echo
net start ntmssvc

REM sleep 60
REM
ECHO #### ntbackup command from the GUI with /um added as a parameter
ECHO #### /um will search for available media in the Free pool, Import pool,
ECHO #### Unrecognized pool, and Backup pool!
REM
echo Running Backup
Echo ..
%SystemRoot%\system32\ntbackup.exe backup "@%NTBackupDataFolder%\%1.bks" /n "%1 %dtt%" /d "%1 %dtt%" /v:no /r:no /rs:no /hc:on /m %2 /j "%1" /l:s /p "%MediaTypePool%" /um

echo %NTBackupDataFolder%\%1.bks

REM
ECHO #### Eject the tape using the tape name
REM
rsm.exe eject /pf"%1 %dtt% - 1" /astart
REM
ECHO #### Email the most recent Backup Log file and Eventlog Information
REM

goto emaillog

ECHO #### Find the appropriate backup log file and test for data
REM
:emaillog
setlocal ENABLEDELAYEDEXPANSION
for /f "Tokens=*" %%a in ('dir "%NTBackupDataFolder%\backup*.log" /b /o:d') do (set file=%%a)
type "%NTBackupDataFolder%\%file%" >> test.txt
findstr /I /M /c:"Backup completed" test.txt
if %errorlevel% == 0 goto typeemail
set backupstatus=failed
pause
goto checkerror


ECHO #### create the E-Mail Text and populate it with data
REM
:typeemail
echo NTBackup Application Eventlog Messages > backuplog.txt
echo ---------------------- >> backuplog.txt
dumpel -l application -c -format tdTSs -d 1 | findstr /c:"NTBackup" >> backuplog.txt
echo ---------------------- >> backuplog.txt
echo NTBackup backup report >> backuplog.txt
echo ---------------------- >> backuplog.txt
type "%NTBackupDataFolder%\%file%" >> backuplog.txt
echo Removable Storage System Eventlog Error Messages >> backuplog.txt
echo ---------------------- >> backuplog.txt
dumpel -l system -c -format tdTSs -d 1 | findstr "*Removable Storage*" >> backuplog.txt
echo ---------------------- >> backuplog.txt
echo Service Control Manager Eventlog Error Messages >> backuplog.txt
echo ---------------------- >> backuplog.txt
dumpel -l system -c -format tdTSs -d 1 | findstr "*Service Control Manager*" >> backuplog.txt
echo ---------------------- >> backuplog.txt

ECHO *** Checking for backup error ***
REM ,1, refers to a backup warning in the applicaiton log for NTBackup
set backupstatus=successful
findstr /I /M /c:",1," backuplog.txt
if %errorlevel% == 1 goto backupgood
set backupstatus=failed
pause
goto checkconsultant

ECHO #### If you want to report only on failures then change the config file to to represent the data below
REM
:backupgood
if "%ReportOn%"=="failed" goto end
goto runreport


ECHO #### E-Mail consultant or group the bad news
REM
:checkerror
if "%ReportToConsultant%"=="no" goto runreport
type "%NTBackupDataFolder%\%file%" | blat.exe - -server %ConsultantSMTPServer% -f %ComputerName%@%DomainName% -to %ConsultantEmail% -s "*** BACKUP FAILED*** on: %ComputerName% : no logs **Backup Error**
goto end

 

ECHO #### E-Mail the consultant the not so good news
REM
:checkconsultant
if "%ReportToConsultant%"=="no" goto runreport
type backuplog.txt | blat.exe - -server %ConsultantSMTPServer% -f %ComputerName%@%DomainName% -to %ConsultantEmail% -s "*** BACKUP ERRORS*** on: %ComputerName% **Backup Error**
goto end

ECHO #### Tell the world the great news
REM
:runreport
if "%ReportTo%"=="none" goto end
if "%ReportTo%"=="printer" goto printlog
ECHO *** This emails the log ***
type backuplog.txt | blat.exe - -server %LogReportSMTPServer% -f %ComputerName%@%DomainName% -to %LogReportEmail% -s "Kiwi Daves NT backupscript for: %ComputerName% Log Report %dtt%"
if "%ReportTo%"=="both" goto printlog
goto end

ECHO #### Print report to config defined printer
REM
:printlog
ECHO *** This prints the log ***
print /d:%LogReportPrinter% "%NTBackupDataFolder%\%file%"
goto end

ECHO *** End of backup log process ***
endlocal
goto end


REM #### if your playing with this - DONT!
REM but if you are, this is just to output to the screen the parameters for use
:usage
cls
@echo off
echo =====================
echo NTBackupScript Usage:
echo =====================

echo ntbackupscript.cmd emaillog
pause
goto end

:norsm
echo Unable to talk to the Removable Storage Manager to refresh the Tape Drive information. Please double-check your TapeDriveGUID value in the config.cmd file. If you reset the RSM database as mentioned in the NTBackupScript Documentation web page, then your TapeDriveGUID has changed!
pause
goto end

ECHO #### delete the temp files - good house keeping
REM
:end
del backuplog.txt
del test.txt
pause
exit

 
0 0 hvala 0
1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice