Tema: Re: q: rman
Autorius: Toxis@ze_yvil_place
Data: 2009-04-10 11:35:58
dekui tau gerasis zhmogau:)

bo su manageriu (naujuojiu, i.e. based) man jis kazhkodel nieko doro nepadro:)


"Vytas :)" <nera@mailo.lt> wrote in message news:grmldt$aqi$1@trimpas.omnitel.net...
Pridedu oraclo pateikiamą bat'uką backupams tvarkyti

Toxis@ze_yvil_place wrote:
> atsakymai po apachia:)
> "Vytas :)" <neturiu@mailo.lt> wrote in message news:grj1s9$lp$1@trimpas.omnitel.net...
>>> vistiek nejama man ish rman.txt failo comandu:)
>> O tai jama komandas tiesiai iš rman konsolės?
> 
> 
> je, jama ir rasho i loga ( jei uzhdedu  nocatalog log='x:\path\log.log' 
> 
> 
> 
>>> beja, vopros na zasypku ar yra skirtumas tarp
>>>
>>> delete nopompt archivelog all completed before 'sysdate-7'
>>>
>>> ir delete noprompt archivelog untill time 'sysdate-7'
>> Na o dėl sintaksės, tai nenoriu sumeluot kuom skiriasi tos komandos - reiktų 
>> paRTFMint :)
> 
> 
> ugu, reiks:)
> blogiausia, kad rmano ash visishkas samouchka, kai kazhkada teko uzhkurinet pirma karta ant clusterinio servo, tai teko pagreitintu budu shiek tiek pramokt:)
> 
>>> gal tiesiog galima recovery cataloge nustatyt, kad jis automatishkai 
>>> trintu failus senesnius nei 7 dienos ir crosscheck'intu (jei to reikia)
>> Na oracle daug ką galima, bet klausimas ar reikia :) Šiaip ant 10g 
>> defaultinė backupavimo politika jau ir taip gan gudriai padaryta, tad iš 
>> enterprise managerio gali su wizzardu puikiausią backup strategiją 
>> pasidaryti su visais senų failų valymais.
> 
> aha! shita reiks prachekint.
> 
>> O rmane yra nurodomas arba "recovery window" arba (nepamenu dabar kaip 
>> tiksliai vadinas) kiek senų backupo kopijų saugoti. Susikonfiginus tai, 
>> rmanas po komandos "delete obsolete" ištrins viską, ko jam nebereikia (senus 
>> backupus bei archivelogus), kad galėtum db "pasendinti" iki nurodyto taško 
>> ir po to atsinaujinti iki paskutinės tranzakcijos arba tam tikro laiko. 
>> Beto, jei gerai pamenu, ant 10g yra tokia sritis "Flash recovery area" ir 
>> jeigu nurodai kad archivelogus dėtų tenais, tada oraclas pats prižiūri, kad 
>> joje neprisikauptų per daug failų ir periodiškai išvalo nereikalingus (bet 
>> tie archivelogai turi būti subackupinti, kad juos išvalytų).
> 
> tai kad vat pagrindine problema ir kilo tada, kai man rods butent toj flash recovery direktorijoj oraklas pradejo durniuot - event logas rekia, kad jis nebegali skaityt\rashyt i failus, nebegali atidaryt (nebuvau (neesu?) padares reopen) o ash tiesa pasakius net nezhinojau, kad ten rmanas yra ji parazita instal shieldas sumete su ora10g ir softu...ash blyn kiek prasikapschiau kol susiprotejau:)
>> Tad gal geriau parašyk, kaip iš viso vyksta backupas ir kaip norėtum kad 
>> vyktų. Gal pavyks tada kažką konkrečiau pasiūlyti...
> 
> problema yra ta, kad esti nemazhai skirtingu vietu. Kai kuriuose yra rmanas, backupinama i raidinius diskus ish ju kiekviena nakti i juostas. Butu viskas shaunu, ale seni archivelogai neishsivalo. Todel reikia kas kazhkiek jungtis, delitint, crosscheckint...
> Kitose gi vietose, po upgreido i ora10g pasirodo irgi uzhsikures rmanas kuris gyvulys irgi backupina, deda viska i defaultinius diskus ir uzhkishineja vieta.. to ten daryt praktishkai nereikia, nes nera jokiu tape draivu, ash uzhsukes ten paprashchiausia dumpinima i tinklini drive'a arba net tiesiog i vietini, ka jie daro su dumpais, ju reikalas, patariam saugotis bent jau i kita pc ar karts nuo karto keptis i dvd, bo tape draivu jie neturi... shituose ash apskrytai pabandysiu nuzhudyt rmana... esme yra butent tuose, kuriuose ji naudojamas ir neishsivalo. Norisi uzhsisukt koki bata idet i schedulleri, kad karta per savaite jis darytu delete noprompt archivelog untill time 'sysdate-7' ir chrosscheck archivelog all; (tiesa nezhinau ar tikrai reikia crosscheckint jei ishvalai ne rankom o per rmana, ale na fsiakyji pozharnaji nepakaneks:)



--------------------------------------------------------------------------------


> @echo off
> REM
> REM The script assumes that user can connect using "/ as sysdba" and Flash 
> REM Recovery Area is enabled.
> REM
> REM =================
> REM Backup procedure
> REM =================
> REM
> REM    For database in NoArchiveLog mode, database is shutdown and an offline 
> REM    backup is done;
> REM    For database in Archive log mode, online backup is done.
> REM
> REM    During the backup procedure, the script stores flash recovery area 
> REM    location by saving complete initialization parameter to 
> REM    ?/DATABASE/SPFILE2INIT.ORA file. This will be used during restore 
> REM    operation to find Flash Recovery Area location. If this file is lost, 
> REM    then user must enter Flash Recovery Area location during restore 
> REM    operation.
> REM
> REM    Two backups are maintained in Flash Recovery Area and the corresponding 
> REM    log files for last two backup job are saved in 
> REM    ?/DATABASE/OXE_BACKUP_CURRENT.LOG and ?/DATABASE/OXE_BACKUP_PREVIOUS.LOG
> REM
> 
> setlocal
> 
> @(
>   echo connect / as sysdba;
>   echo set head off
>   echo set echo off
>   echo set linesize 515
>   echo variable var varchar2^(512^)^;
>   echo execute :var := sys.dbms_backup_restore.normalizefilename^(^'FRA_LOC^'^)^;
>   echo spool %temp%\backup_rmanlog.log
>   echo select sys.dbms_backup_restore.normalizefilename^(^'OXE_BACKUP_CURRENT.LOG^'^) BACKUP_RMANLOG from dual^;
>   echo exit^;
> ) > %temp%\backup_rmanlog.sql
> sqlplus /nolog @%temp%\backup_rmanlog.sql >nul
> FOR /F %%i in (%temp%\backup_rmanlog.log) do set BACKUP_RMANLOG=%%i
> 
> @(
>   echo connect / as sysdba;
>   echo set head off
>   echo set echo off
>   echo set linesize 515
>   echo variable var varchar2^(512^)^;
>   echo execute :var := sys.dbms_backup_restore.normalizefilename^(^'FRA_LOC^'^)^;
>   echo spool %temp%\backup_rmanprevlog.log
>   echo select sys.dbms_backup_restore.normalizefilename^(^'OXE_BACKUP_PREVIOUS.LOG^'^) BACKUP_RMANLOG from dual^;
>   echo exit^;
> ) > %temp%\backup_rmanprevlog.sql
> sqlplus /nolog @%temp%\backup_rmanprevlog.sql >nul
> FOR /F %%i in (%temp%\backup_rmanprevlog.log) do set BACKUP_RMANPREVLOG=%%i
> 
> @(
>   echo connect / as sysdba;
>   echo set head off
>   echo set echo off
>   echo set linesize 515
>   echo spool %temp%\backup_fra.log
>   echo select value from v$parameter where lower^(name^)=^'db_recovery_file_dest^'^;
>   echo exit^;
> ) > %temp%\backup_fra.sql
> sqlplus /nolog @%temp%\backup_fra.sql >nul
> set BACKUP_FRA=
> FOR /F %%i in (%temp%\backup_fra.log) do set BACKUP_FRA=%%i
> if "%BACKUP_FRA%"=="" set Errorstr=         Flash Recovery Area is not enabled & goto :backupfailederr
> 
> @(
>   echo connect / as sysdba;
>   echo set head off
>   echo set echo off
>   echo set linesize 515
>   echo spool %temp%\backup_fra2.log
>   echo select sys.dbms_backup_restore.normalizefilename^(^'%BACKUP_FRA%^'^) BACKUP_FRA from dual^;
>   echo exit^;
> ) > %temp%\backup_fra2.sql
> sqlplus /nolog @%temp%\backup_fra2.sql >nul
> FOR /F %%i in (%temp%\backup_fra2.log) do set BACKUP_FRA=%%i
> 
> @(
>   echo connect / as sysdba;
>   echo set head off
>   echo set echo off
>   echo set linesize 515
>   echo variable var varchar2^(512^)^;
>   echo execute :var := sys.dbms_backup_restore.normalizefilename^(^'SPFILE2INIT^'^)^;
>   echo spool %temp%\backup_spfile2init.log
>   echo select sys.dbms_backup_restore.normalizefilename^(^'SPFILE2INIT.ORA^'^) spfile2init from dual^;
>   echo exit^;
> ) > %temp%\backup_spfile2init.sql
> sqlplus /nolog @%temp%\backup_spfile2init.sql >nul
> FOR /F %%i in (%temp%\backup_spfile2init.log) do set SPFILE2INIT=%%i
> 
> @(
>   echo connect / as sysdba;
>   echo set head off
>   echo set echo off
>   echo spool %temp%\logmode.log
>   echo select log_mode from v$database^;
>   echo exit^;
> ) > %temp%\logmode.sql
> sqlplus /nolog @%temp%\logmode.sql >nul
> FOR /F %%i in (%temp%\logmode.log) do set LOGMODE=%%i
> 
> if "%LOGMODE%" == "NOARCHIVELOG" goto process_noarchivelog
> if "%LOGMODE%" == "ARCHIVELOG" goto process_archivelog
> set Errorstr=         Unknown log mode : %LOGMODE%
> goto :backupfailederr
> 
> :process_noarchivelog
>   echo Warning: Log archiving ^(ARCHIVELOG mode^) is currently disabled. If
>   echo you restore the database from this backup, any transactions that take
>   echo place between this backup and the next backup will be lost. It is
>   echo recommended that you enable ARCHIVELOG mode before proceeding so 
>   echo that all transactions can be recovered upon restore. See the section
>   echo 'Enabling ARCHIVELOG Mode...' in the online help for instructions.
>   echo Backup with log archiving disabled will shut down and restart the
>   set /p inp="database. Are you sure [Y/N]? "
> :checkinp
> if /i "%inp%" == "Y" goto :confirmedyes
> if /i "%inp%" == "n" exit & goto :EOF
> :Askagain
> set /p inp=
> goto :checkinp
> 
> :confirmedyes
> if exist %BACKUP_RMANLOG% copy %BACKUP_RMANLOG% %BACKUP_RMANPREVLOG% /y >nul
> echo Backup in progress...
> @(
>   echo set echo on^;
>   echo shutdown immediate^;
>   echo startup mount^;
>   echo configure controlfile autobackup format for device type disk clear^;
>   echo configure retention policy to redundancy 2^;
>   echo configure controlfile autobackup on^;
>   echo sql ^"create pfile=^'^'%SPFILE2INIT%^'^' from spfile^"^;
>   echo backup as backupset device type disk database^;
>   echo configure controlfile autobackup off^;
>   echo alter database open^;
>   echo delete noprompt obsolete^;
> ) > %temp%\backup_rman.dat
> rman target / @%temp%\backup_rman.dat trace "%BACKUP_RMANLOG%"
> if not %errorlevel% == 0 set Errorstr=         RMAN Error - See log for details & goto :backupfailederr
> 
> goto :backupsucess
> 
> :process_archivelog
> if exist %BACKUP_RMANLOG% copy %BACKUP_RMANLOG% %BACKUP_RMANPREVLOG% /y >nul
> echo Doing online backup of the database.
> @(
>   echo set echo on^;
>   echo configure controlfile autobackup format for device type disk clear^;
>   echo configure retention policy to redundancy 2^;
>   echo configure controlfile autobackup on^;
>   echo sql ^"create pfile=^'^'%SPFILE2INIT%^'^' from spfile^"^;
>   echo backup as backupset device type disk database^;
>   echo configure controlfile autobackup off^;
>   echo sql ^'alter system archive log current^'^;
>   echo delete noprompt obsolete^;
> ) > %temp%\backup_rman.dat
> rman target / @%temp%\backup_rman.dat trace "%BACKUP_RMANLOG%"
> if not %errorlevel% == 0 set Errorstr=         RMAN Error - See log for details & goto :backupfailederr
> 
> REM Switch an archived log if database is open
> @(
>   echo set echo on^;
>   echo sql ^'alter system archive log current^'^;
> ) > %temp%\backup_rman2.dat
> rman target / @%temp%\backup_rman2.dat trace "%BACKUP_RMANLOG%"
> goto :backupsucess
> 
> :backupsucess
> echo Backup of the database succeeded.
> echo Log file is at %BACKUP_RMANLOG%.
> pause Press any key to exit
> exit
> goto :EOF
> 
> :backupfailederr
> echo ====================   ERROR =============================
> echo          Backup of the database failed.
> echo %Errorstr%.
> echo          Log file is at %BACKUP_RMANLOG%.
> echo ====================   ERROR =============================
> pause Press any key to exit
> exit
> goto :EOF
>