真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

oracle腳本如何寫 oracle sql腳本

oracle rman備份腳本怎么寫

在ORACLE數(shù)據(jù)庫中,RMAN備份的腳本非常多,下面介紹一例shell腳本如何通過RMAN備份,以及FTP上傳RMAN備份文件以及歸檔日志文件的腳本。

成都創(chuàng)新互聯(lián)公司為企業(yè)級客戶提高一站式互聯(lián)網(wǎng)+設(shè)計(jì)服務(wù),主要包括網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站建設(shè)、成都app軟件開發(fā)、重慶小程序開發(fā)公司、宣傳片制作、LOGO設(shè)計(jì)等,幫助客戶快速提升營銷能力和企業(yè)形象,創(chuàng)新互聯(lián)各部門都有經(jīng)驗(yàn)豐富的經(jīng)驗(yàn),可以確保每一個(gè)作品的質(zhì)量和創(chuàng)作周期,同時(shí)每年都有很多新員工加入,為我們帶來大量新的創(chuàng)意。 

fullback.sh 里面調(diào)用RMAN命令做數(shù)據(jù)庫備份,它使用的cmdfile為/home/oracle/backup/bin/fullback.rcv,同時(shí)在/home/oracle/backup/logs目錄下生成日志文件。

1: [oracle@DB-Server bin]$ more fullback.sh

2:

3: #!/bin/bash

4:

5: export ORACLE_BASE=/u01/app/oracle

6:

7: export ORACLE_SID=gps

8:

9: ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME

10:

11: TMP=/tmp; export TMP

12:

13: TMPDIR=$TMP; export TMPDIR

14:

15: PATH=/usr/sbin:$PATH; export PATH

16:

17: PATH=$ORACLE_HOME/bin:$PATH; export PATH

18:

19: LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH

20:

21: CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;

22:

23: export CLASSPATH

24:

25: TODAY=`date +%Y_%m_%d`

26:

27: rman nocatalog target / cmdfile /home/oracle/backup/bin/fullback.rcv log /home/oracle/backup/logs/fullbackup_$TODAY.log

28:

29: /home/oracle/backup/bin/ftpbackup.sh

30:

fullback.rcv文件非常簡單, 如下所示:

1: [oracle@DB-Server bin]$ more /home/oracle/backup/bin/fullback.rcv

2:

3: run{

4:

5: allocate channel c4 type disk;

6:

7: backup as compressed backupset

8:

9: skip inaccessible

10:

11: tag fullbackupwitharchivelog

12:

13: (database);

14:

15: backup current controlfile;

16:

17: backup spfile;

18:

19: sql "alter system archive log current";

20:

21: delete noprompt obsolete;

22:

23: release channel c4;

24:

25: }

26:

RMAN生成的備份文件,需要通過FTP上傳到FTP服務(wù)器,一則數(shù)據(jù)庫服務(wù)器沒有這么多空間存儲(chǔ)多天的備份,二則是出于容災(zāi)、數(shù)據(jù)安全需要。

下面腳本中FTP服務(wù)器,用戶名密碼均使用xxx替代,在實(shí)際環(huán)境中,使用具體的信息替代即可。

1: [oracle@DB-Server bin]$ more ftpbackup.sh

2:

3: #!/bin/sh、

4:

5: rm -f /home/oracle/.netrc

6:

7: date_yesterday=`date -d'yesterday' +%Y_%m_%d`

8:

9: date_today=`date +%Y_%m_%d`

10:

11: echo "default login xxxx password xxxxxx" /home/oracle/.netrc

12:

13: echo "macdef init" /home/oracle/.netrc

14:

15: echo "binary" /home/oracle/.netrc

16:

17: echo "cd archivelog" /home/oracle/.netrc

18:

19: echo "mkdir $date_yesterday" /home/oracle/.netrc

20:

21: echo "cd $date_yesterday" /home/oracle/.netrc

22:

23: echo "lcd /u04/flash_recovery_area/gps/archivelog/$date_yesterday" /home/oracle/.netrc

24:

25: echo "mput *" /home/oracle/.netrc

26:

27: echo "cd .." /home/oracle/.netrc

28:

29: echo "mkdir $date_today" /home/oracle/.netrc

30:

31: echo "cd $date_today" /home/oracle/.netrc

32:

33: echo "lcd /u04/flash_recovery_area/gps/archivelog/$date_today" /home/oracle/.netrc

34:

35: echo "mput * "/home/oracle/.netrc

36:

37: echo "cd .." /home/oracle/.netrc

38:

39: echo "cd ../backupset" /home/oracle/.netrc

40:

41: echo "mkdir $date_today" /home/oracle/.netrc

42:

43: echo "cd $date_today" /home/oracle/.netrc

44:

45: echo "lcd /u04/flash_recovery_area/gps/backupset/$date_today" /home/oracle/.netrc

46:

47: echo "mput *" /home/oracle/.netrc

48:

49: echo "cd .." /home/oracle/.netrc

50:

51: echo "cd ../autobackup" /home/oracle/.netrc

52:

53: echo "mkdir $date_today" /home/oracle/.netrc

54:

55: echo "cd $date_today" /home/oracle/.netrc

56:

57: echo "lcd /u04/flash_recovery_area/gps/autobackup/$date_today" /home/oracle/.netrc

58:

59: echo "mput *" /home/oracle/.netrc

60:

61: echo "quit" /home/oracle/.netrc

62:

63: echo "" /home/oracle/.netrc

64:

65: chmod 600 /home/oracle/.netrc

66:

67: ftp -i -v xxx.xxx.xxx.xxx 8021 /home/oracle/backup/logs/ftp$date_today.log 21

68:

另外,關(guān)于歸檔日志也需要每隔2小時(shí)上傳一次到FTP服務(wù)器,2小時(shí)上傳一次歸檔日志的shell腳本如下所示:

1: [oracle@DB-Server bin]$ more ftp2hours.sh

2:

3: #!/bin/sh

4:

5: rm -f /home/oracle/.netrc

6:

7: date_yesterday=`date -d'yesterday' +%Y_%m_%d`

8:

9: date_today=`date +%Y_%m_%d`

10:

11: echo "default login xxxx password xxxx" /home/oracle/.netrc

12:

13: echo "macdef init" /home/oracle/.netrc

14:

15: echo "binary" /home/oracle/.netrc

16:

17: echo "cd archivelog" /home/oracle/.netrc

18:

19: echo "mkdir $date_today" /home/oracle/.netrc

20:

21: echo "cd $date_today" /home/oracle/.netrc

22:

23: echo "lcd /u04/flash_recovery_area/gps/archivelog/$date_today" /home/oracle/.netrc

24:

25: echo "mput * "/home/oracle/.netrc

26:

27: echo "quit" /home/oracle/.netrc

28:

29: echo "" /home/oracle/.netrc

30:

31: chmod 600 /home/oracle/.netrc

32:

33: ftp -i -v xxx.xxx.xxx.xxx 8021 /home/oracle/backup/logs/ftp2hours.$date_today.log 21

34:

最后需要將RMAN備份生成的日志文件,以及FTP上傳備份文件以及歸檔日志的記錄通過郵件形式發(fā)送給DBA或系統(tǒng)管理員,

1: [oracle@DB-Server bin]$ more chkbackandmail.sh

2: #!/bin/bash

3: rm -f /home/oracle/backup/bin/sendmail.pl

4: date_today=`date +%Y_%m_%d`

5: subject="Oracle Backup Alert Service on $date_today"

6: content="Dear colleagues,

7:

8: Attached please find the logs of xxx(xxx.xxx.xxx.xxx) oracle database backup and transfer to FTP Server(xxx.xxx.xxx.xxx), please

9: review the file and check whether the backup succeeded or not,and double check all backups have been dumped to tape, many tha

10: nks

11:

12:

13:

14:

15: Best regards

16: Oracle Alert Services

17:

18: "

19: file="/home/oracle/backup/logs/fullbackup_$date_today.log,/home/oracle/backup/logs/ftp$date_today.log"

20: echo "#!/usr/bin/perl" /home/oracle/backup/bin/sendmail.pl

21: echo "use Mail::Sender;" /home/oracle/backup/bin/sendmail.pl

22: echo "\$sender = new Mail::Sender {smtp = 'xxx.xxx.xxx.xxx', from = 'xxxx@xxx.com'}; " /home/oracle/backup/bin/sendmai

23: l.pl

24: echo "\$sender-MailFile({to = 'xxx@esquel.com'," /home/oracle/backup/bin/sendmail.pl

25: echo "cc='xxx@xxx.com,xxx@xxx.com,xxx@xxx.com'," /home/oracle/backup/b

26: in/sendmail.pl

27: echo "subject = '$subject'," /home/oracle/backup/bin/sendmail.pl

28: echo "msg = '$content'," /home/oracle/backup/bin/sendmail.pl

29: echo "file = '$file'});" /home/oracle/backup/bin/sendmail.pl

30: perl /home/oracle/backup/bin/sendmail.pl

最后在Crontab 作業(yè)里面配置調(diào)用這些shell腳本。例如如下所示,在1:01分執(zhí)行fullback.sh ,每隔兩個(gè)小時(shí)(例如0:50、2:50...)執(zhí)行一次ftp2hours.sh, 在每天早上8:40執(zhí)行chkbackandmail.sh 發(fā)送fullback.sh 以及ftp2hour.sh的執(zhí)行日志記錄。

oracle數(shù)據(jù)庫這樣的(照片所示)rman備份腳本怎么寫

只考慮備份,不考慮其他情況下:

root下的3個(gè)rman備份級別的腳本:

#cat

rman_0.sql

backup

incremental

level

database;

#cat

rman_1.sql

backup

incremental

level

1

database;

#cat

rman_1c.sql

backup

incremental

level

1

cumulative

database;

root下的調(diào)用rman腳本

#cat

rman_0.sh

#!/bin/bash

su

-

oracle

-c

"rman

target

sys/SHUIMITAO@rabbit

@/root/rman_0.sql"

#cat

rman_1.sh

#!/bin/bash

su

-

oracle

-c

"rman

target

sys/SHUIMITAO@rabbit

@/root/rman_1.sql"

#cat

rman_1c.sh

#!/bin/bash

su

-

oracle

-c

"rman

target

sys/SHUIMITAO@rabbit

@/root/rman_1c.sql"

root的計(jì)劃任務(wù):

#crontab

-e

1

*

*

/root/rman_0.sh

2

*

*

1

/root/rman_1.sh

2

*

*

2

/root/rman_1.sh

3

*

*

3

/root/rman_1c.sh

2

*

*

4

/root/rman_1.sh

3

*

*

5

/root/rman_1c.sh

2

*

*

6

/root/rman_1.sh

11g里只有0和1兩個(gè)備份級別,請自行對應(yīng)oracle低版本

level

0是full

level

1是差異增量備份

--和前一次備份比較,將這個(gè)期間改變的數(shù)據(jù)備份下來

level

1c是累計(jì)增量備份

--和比他小得級別相比(即全備份),改變的數(shù)據(jù)備份

然后根據(jù)實(shí)際情況還要將備份的策略往腳本添加

Oracle數(shù)據(jù)庫備份腳本怎么寫?

沒必要用root權(quán)限執(zhí)行,oracle用戶同樣可以執(zhí)行crontab計(jì)劃任務(wù)

1、su - oracle

crontab -e

0 4 * * 0 /home/oracle/exp.sh 21 /home/oracle/script_exp.log;

0~59 表示分

0~23 表示小時(shí)

1~31 表示日

1~12 表示月份

0~6 表示星期(其中0表示星期日)

2、cat /home/oracle/exp.sh

. ~/.bash_profile

bakdir=/opt/dbbak

logdir=/home/oracle/dbbak

rq=$(date +%Y%m%d)

exp system/***** owner=jysh file=${bakdir}/jysh_${rq}.dmp log=${logdir}/jysh_${rq}.log;

find ${bakdir} -type f -mtime +30 -exec rm -rf {} \;

oracle數(shù)據(jù)庫,批量插入數(shù)據(jù)腳本

批量插入數(shù)據(jù)腳本

1、第一種批量插入數(shù)據(jù)腳本,可以基本滿足要求。理解上較為簡單,所以這個(gè)最常用。

NEXTVAL和CURRVAL的區(qū)別:

1、如果 sequence.CURRVAL 和 sequence.NEXTVAL 都出現(xiàn)在一個(gè) SQL 語句中,則序列只增加一次。在這種情況下,每個(gè) sequence.CURRVAL 和 sequence.NEXTVAL 表達(dá)式都返回相同的值,不管在語句中sequence.CURRVAL 和 sequence.NEXTVAL 的順序。

執(zhí)行腳本結(jié)果如下:

3、兩個(gè)表,同時(shí)批量插入數(shù)據(jù)的腳本

3、

4、 涉及子表時(shí),批量插入數(shù)據(jù)腳本,

5、 批量修改數(shù)據(jù) :

時(shí)間取數(shù)方式:

一、SYSTIMESTAMP(取當(dāng)前系統(tǒng)值)

二、SYSDATE(取當(dāng)前系統(tǒng)值,但只精確到時(shí),分和秒都為0)

三、固定值為:TO_TIMESTAMP ('2019-2-12 15:24:45.703000', 'yyyy-mm-dd hh24:mi:ss.ff6')

把固定的字段改為變量:

方式一:’||i||’ 例:’{“no”:“111’||i||’”}’(此方式)

方式二:concat 例:concat(concat(’{“blNo”:111"’,i),’"}’)

linux下備份oracle的腳本怎么寫

把下面的代碼保存為服務(wù)器端的腳本,執(zhí)行即可。PS:需要自己替換一下雙引號(hào)中的內(nèi)容

#!/bin/sh

. $HOME/.bash_profile

export ORACLE_SID="你的數(shù)據(jù)庫的SID"

CutDATE=`date '+%Y-%m%d-%H%M'`

DATE=`date -d '-2 day' '+%Y-%m%d'`

export NLS_LANG="你的字符集設(shè)定"

exp "具有權(quán)限的賬號(hào)"/"密碼" file=/home/oracle/2014/"你的數(shù)據(jù)庫的SID"_$CutDATE.dmp log=/home/oracle/2014/"你的數(shù)據(jù)庫的SID"_$CutDATE.log owner=user1,user2

oracle insert into 腳本怎么寫

INSERT INTO BOOK(bookid,name,price)? VALUES('100123','oracle ',54);

或者

INSERT INTO tablename(bookid,name,price)

SELECT '100123','oracle,54 FROM DUAL;

總結(jié)下Oracle 中的Insert用法

1.標(biāo)準(zhǔn)Insert --單表單行插入

語法:

INSERT INTO table [(column1,column2,...)] VALUE (value1,value2,...)

例子:

insert into dep (dep_id,dep_name) values(1,'技術(shù)部');

2, 無條件 Insert all --多表多行插入

語法:

INSERT [ALL] [condition_insert_clause]

[insert_into_clause values_clause] (subquery)

示例:

INSERT ALL

INTO sal_history(emp_id,hire_date,salary) values (empid,hiredate,sal)

INTO mgr_history(emp_id,manager_id,salary) values (empid,hiredate,sal)

SELECT employee_id empid,hire_date hiredate,salary sal,manager_id mgr

FROM employees

WHERE employee_id200;

3,有條件的Insert

語法:

INSERT [ALL | FIRST]

WHEN condition THEN insert_into_clause values_clause

[WHEN condition THEN] [insert_into_clause values_clause]

......

[ELSE] [insert_into_clause values_clause]

Subquery;

示例:

Insert All

when id5 then into z_test1(id, name) values(id,name)

when id2 then into z_test2(id) values(id)

else into z_test3 values(name)

select id,name from z_test;

4, 旋轉(zhuǎn)Insert (pivoting insert)

create table sales_source_data (

employee_id number(6),

week_id number(2),

sales_mon number(8,2),

sales_tue number(8,2),

sales_wed number(8,2),

sales_thur number(8,2),

sales_fri number(8,2)

);

insert into sales_source_data values (176,6,2000,3000,4000,5000,6000);

create table sales_info (

employee_id number(6),

week number(2),

sales number(8,2)

);

示例如下:

insert all

into sales_info values(employee_id,week_id,sales_mon)

into sales_info values(employee_id,week_id,sales_tue)

into sales_info values(employee_id,week_id,sales_wed)

into sales_info values(employee_id,week_id,sales_thur)

into sales_info values(employee_id,week_id,sales_fri)

select employee_id,week_id,sales_mon,sales_tue,

sales_wed,sales_thur,sales_fri

from sales_source_data;


網(wǎng)頁標(biāo)題:oracle腳本如何寫 oracle sql腳本
文章地址:http://weahome.cn/article/hhiggp.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部