Thứ Sáu, 5 tháng 11, 2021

Script backup level 0, level 1, backup read only dữ liệu cũ

Mục đích: Với các Database dung lượng lớn (>5TB) thì thường có dữ liệu cũ, không thay đổi do đó để giảm thời gian backup trước giờ làm việc (thường là 8h00 hàng ngày) ta phải read only/offline tablespace cũ để giảm dung lượng backup cho các tablespace chạy chính. Sau đây tôi sẽ chia sẻ với các bạn các script để backup để đảm bảo an toàn, nhanh chóng cho Database:

Script backup level 0:
$ vi  /u01/oracle/backup_db/scripts/backup_db_level_0.rcv
RUN
{
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
DELETE BACKUP COMPLETED BEFORE 'SYSDATE-4' DEVICE TYPE DISK;
ALLOCATE CHANNEL c1 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c1_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c2 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c2_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c3 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c3_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c4 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c4_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c5 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c5_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c6 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c6_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c7 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c7_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c8 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c8_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c9 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c9_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c10 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c10_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c11 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c11_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c12 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c12_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c13 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c13_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c14 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c14_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c15 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c15_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c16 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c16_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c17 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c17_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c18 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c18_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c19 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c19_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c20 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c20_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c21 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c21_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c22 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c22_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c23 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c23_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c24 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c24_dbaviet_level0_ora_df%T_s%s_s%p';
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 0 DATABASE FILESPERSET 10 SKIP READONLY SKIP OFFLINE   MAXSETSIZE 40 G TAG LEVEL0;
BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FILESPERSET 4 TAG ARCH delete input;
#Delete noprompt archivelog until time 'sysdate-1';
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE OBSOLETE;
}

-- Tạo file shell
$ vi /u01/oracle/backup_db/scripts/run_backup_db_level_0.sh 
target='target /'
rcvcat='nocatalog'
freq=24
time=`date '+%H%M%S'`
cmdfile=/u01/oracle/backup_db/scripts/backup_db_level_0.rcv
msglog=/u01/oracle/backup_db/log/level0/rman_level0_$time.log
#rman $target $rcvcat cmdfile $cmdfile msglog $msglog
rman target / cmdfile=/u01/oracle/backup_db/scripts/end_backup.rcv
rman $target $rcvcat cmdfile $cmdfile 
exit

-- Sau đó đặt vào crontab Backup full (level 0) vào 00h00 thứ 4, chủ nhật
00 00 * * 3,6 "/u01/oracle/backup_db/scripts/run_backup_db_level_0.sh 
Script backup level 1
$ vi /u01/oracle/backup_db/scripts/backup_db_level_1.rcv
RUN
{
Crosscheck archivelog all;
Delete noprompt expired archivelog all;
DELETE BACKUP COMPLETED BEFORE 'SYSDATE-4' DEVICE TYPE DISK;
ALLOCATE CHANNEL c1 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c1_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c2 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c2_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c3 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c3_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c4 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c4_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c5 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c5_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c6 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c6_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c7 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c7_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c8 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c8_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c9 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c9_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c10 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c10_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c11 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c11_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c12 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c12_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c13 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c13_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c14 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c14_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c15 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c15_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c16 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c16_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c17 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c17_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c18 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c18_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c19 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c19_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c20 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c20_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c21 DEVICE TYPE DISK  format '/s03/backup_db/dbaviet/c21_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c22 DEVICE TYPE DISK  format '/s04/backup_db/dbaviet/c22_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c23 DEVICE TYPE DISK  format '/s01/backup_db/dbaviet/c23_dbaviet_level0_ora_df%T_s%s_s%p';
ALLOCATE CHANNEL c24 DEVICE TYPE DISK  format '/s02/backup_db/dbaviet/c24_dbaviet_level0_ora_df%T_s%s_s%p';
BACKUP AS COMPRESSED BACKUPSET INCREMENTAL LEVEL 1 DATABASE FILESPERSET 10 SKIP READONLY SKIP OFFLINE  MAXSETSIZE 40 G TAG LEVEL1 ;
BACKUP AS COMPRESSED BACKUPSET ARCHIVELOG ALL FILESPERSET 10 TAG ARCH DELETE INPUT;
#Delete noprompt archivelog until time 'sysdate-1';
CROSSCHECK BACKUP;
DELETE NOPROMPT EXPIRED BACKUP;
DELETE OBSOLETE;
}

-- Tạo file shell
$ vi  /u01/oracle/backup_db/scripts/run_backup_db_level_1.sh 
target='target /'
rcvcat='nocatalog'
freq=24
time=`date '+%H%M%S'`
cmdfile=/u01/oracle/backup_db/scripts/backup_db_level_1.rcv
msglog=/u01/oracle/backup_db/log/level1/rman_level1_$time.log
#rman $target $rcvcat cmdfile $cmdfile msglog $msglog
rman target / cmdfile=/u01/oracle/backup_db/scripts/end_backup.rcv
rman $target $rcvcat cmdfile $cmdfile 
exit

 -- Backup incremental (level 1) vào 00h00 các ngày còn lại
00 00 * * 1,2,4,5,0 "/u01/oracle/backup_db/scripts/run_backup_db_level_1.sh "
Script backup dữ liệu cũ Read Only:

--Backup Read Only, Offline DATA, INDX 2011 - 2016: 358GB can backup, backup ra 51GB  (1/7)
--Nếu backup chậm read only tiep DATA2017 

--1.Tạo script

$ vi /u01/oracle/backup_db/scripts/backup_tbs_readonly.rcv 
RUN {
ALLOCATE CHANNEL RMAN_DISK01 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK02 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK03 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK04 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK05 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK06 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK07 TYPE DISK;
ALLOCATE CHANNEL RMAN_DISK08 TYPE DISK;
BACKUP AS COMPRESSED BACKUPSET TABLESPACE DATA2015,DATA2016,INDX2016,DATA2013,INDX2013,DATA2014,INDX2014,DATA2011,INDX2011,DATA2012,INDX2012,INDX2015 FORMAT '/s05/backup_reado
nly/dbaviet/tbs_reaonly_%T_%d_%U' FILESPERSET 10 MAXSETSIZE 40 G TAG TBS_READONLY;
RELEASE CHANNEL RMAN_DISK01;
RELEASE CHANNEL RMAN_DISK02;
RELEASE CHANNEL RMAN_DISK03;
RELEASE CHANNEL RMAN_DISK04;
RELEASE CHANNEL RMAN_DISK05;
RELEASE CHANNEL RMAN_DISK06;
RELEASE CHANNEL RMAN_DISK07;
RELEASE CHANNEL RMAN_DISK08;
}
EXIT;

$ vi /u01/oracle/backup_db/scripts/run_backup_tbs_readonly.sh 
target='target /'
rcvcat='nocatalog'
freq=24
time=`date '+%H%M%S'`
cmdfile=/u01/oracle/backup_db/scripts/backup_tbs_readonly.rcv
msglog=/u01/oracle/backup_db/log/rman_tbs_readonly_$time.log
#rman $target $rcvcat cmdfile $cmdfile msglog $msglog
rman target / cmdfile=/u01/oracle/backup_db/scripts/end_backup.rcv
rman $target $rcvcat cmdfile $cmdfile 
exit


--2. Sau khi backup xong doi ten tu  /s05/backup_readonly/dbaviet thanh /s05/backup_reado
nly/dbaviet.20171127

Doi quyen root de tranh bi xoa
# chown -Rf root /s05/backup_readonly/dbaviet.20171127


--3.Khi can su dung
# mv /s05/backup_readonly/dbaviet.20171127.20171127 /s05/backup_readonly/dbaviet.20171127
# chown -Rf oracle:oinstall /s05/backup_readonly/dbaviet.20171127
Hy vọng hữu ích cho bạn.
=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile: 0902912888
⚡️ Skype: tranbinh48ca
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: http://bit.ly/ytb_binhoraclemaster
👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhoracle
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,khóa học pl/sql, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle weblogic, middleware, hoc solaris, hoc linux, hoc aix, unix, oracle oca, oracle ocp, oracle ocm

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master