您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關DM7中怎么利用disql管理備份,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
1. 概述
管理備份一個重要的目的是刪除不再需要的備份,DM7沒有提供自動刪除過期備份的功能,刪除備份需要手動執行。備份管理相關系統過程與函數總結如下:
SF_BAKSET_BACKUP_DIR_ADD:添加備份目錄。
SF_BAKSET_BACKUP_DIR_REMOVE:指定刪除內存中的備份目錄。
SF_BAKSET_BACKUP_DIR_REMOVE_ALL:刪除內存中全部的備份目錄。
SF_BAKSET_CHECK:對備份集進行校驗。
SF_BAKSET_REMOVE:刪除指定設備類型和指定備份集目錄的備份集。
SF_BAKSET_REMOVE_BATCH:批量刪除滿足指定條件的所有備份集。
SP_DB_BAKSET_REMOVE_BATCH:批量刪除指定時間之前的數據庫備份集。
SP_TS_BAKSET_REMOVE_BATCH:批量刪除指定表空間對象及指定時間之前的表空間備份集。
SP_TAB_BAKSET_REMOVE_BATCH:批量刪除指定表對象及指定時間之前的表備份集。
SP_ARCH_BAKSET_REMOVE_BATCH:批量刪除指定條件的歸檔備份集。
備份管理相關動態視圖總結如下:
V$BACKUPSET:顯示備份集基本信息。
V$BACKUPSET_DBINFO:顯示備份集的數據庫相關信息。
V$BACKUPSET_DBF:顯示備份集中數據文件的相關信息。
V$BACKUPSET_ARCH:顯示備份集的歸檔信息。
V$BACKUPSET_BKP:顯示備份集的備份片信息。
V$BACKUPSET_SEARCH_DIRS:顯示備份集搜索目錄。
V$BACKUPSET_TABLE:顯示表備份集中備份表信息。
V$BACKUPSET_SUBS:顯示并行備份中生成的子備份集信息。
SF_BAKSET_BACKUP_DIR_ADD添加備份目錄僅對當前會話有效。調用刪除備份等函數或查看動態視圖時要先調用SF_BAKSET_BACKUP_DIR_ADD添加備份目錄,否則僅搜索默認備份路徑下的備份集。
2. 備份目錄管理
這里的備份目錄是指備份集搜索目錄,這些目錄被記錄在內存中,當執行動態視圖(參見3.2.4.4 備份信息查看)或批量刪除備份集時,均會從這些指定目錄中先搜索所有備份集信息。
本節主要內容包括:
SF_BAKSET_BACKUP_DIR_ADD SF_BAKSET_BACKUP_DIR_REMOVE SF_BAKSET_BACKUP_DIR_REMOVE_ALL
SF_BAKSET_BACKUP_DIR_ADD函數
添加備份目錄。若添加目錄已經存在或者為庫默認備份路徑,則認為已經存在,不添加,但也不報錯。
定義:
INT SF_BAKSET_BACKUP_DIR_ADD( device_type varchar, backup_dir varchar(256) )
參數說明:
device_type:待添加的備份目錄對應存儲介質類型,DISK或者TAPE。
backup_dir:待添加的備份目錄。
返回值:
1:目錄添加成功;其它情況下報錯。
舉例說明:
SQL> select sf_bakset_backup_dir_add('disk','arch_backup_lsn_15092082_15092086'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','arch_backup_lsn_15092082_15092086') ---------- -------------------------------------------------------------------- 1 1 used time: 26.411(ms). Execute id is 1569.
SF_BAKSET_BACKUP_DIR_REMOVE函數
刪除備份目錄。若刪除目錄為庫默認備份路徑,不進行刪除,認為刪除失敗。若指定目錄存在于記錄的合法目錄中,則刪除;不存在或者為空則跳過,正常返回。
定義:
INT SF_BAKSET_BACKUP_DIR_REMOVE ( device_type varchar, backup_dir varchar(256) )
參數說明:
device_type:待刪除的備份目錄對應存儲介質類型。待刪除的備份目錄對應存儲介質類型,DISK或者TAPE。
backup_dir:待刪除的備份目錄。
返回值:
1:目錄刪除成功;其他情況報錯。
舉例說明:
SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ----------------------------------- 1 arch_backup_lsn_15092082_15092086 2 /dm_home/dmdba/dmdbms/data/jydm/bak used time: 36.620(ms). Execute id is 1573. SQL> select sf_bakset_backup_dir_remove('disk','arch_backup_lsn_15092082_15092086'); LINEID SF_BAKSET_BACKUP_DIR_REMOVE('disk','arch_backup_lsn_15092082_15092086') ---------- ----------------------------------------------------------------------- 1 1 used time: 1.057(ms). Execute id is 1575. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ----------------------------------- 1 /dm_home/dmdba/dmdbms/data/jydm/bak used time: 0.987(ms). Execute id is 1577.
SF_BAKSET_BACKUP_DIR_REMOVE_ALL函數清理全部備份目錄,默認備份目錄除外。
定義:
INT SF_BAKSET_BACKUP_DIR_REMOVE_ALL ()
返回值:
1:目錄全部清理成功;其它情況下報錯。
舉例說明:
SQL> select sf_bakset_backup_dir_remove_all(); LINEID SF_BAKSET_BACKUP_DIR_REMOVE_ALL() ---------- --------------------------------- 1 1 used time: 1.019(ms). Execute id is 1580.
3. 備份集管理(備份集校驗與刪除)
本節介紹備份管理中最重要的功能,備份集校驗和備份集刪除。單個備份集刪除時并行備份中地子備份集不允許單獨刪除;在給定備份集搜
集目錄中發現存在引用刪除備份集作為基備份的需要執行級聯刪除,默認報錯。批量刪除備份集時,跳過收集到的單獨的子備份集。主要內
容如下:
SF_BAKSET_CHECK SF_BAKSET_REMOVE SF_BAKSET_REMOVE_BATCH SP_DB_BAKSET_REMOVE_BATCH SP_TS_BAKSET_REMOVE_BATCH SP_TAB_BAKSET_REMOVE_BATCH SP_ARCH_BAKSET_REMOVE_BATCH
SF_BAKSET_CHECK函數對備份集進行校驗。
定義:
INT SF_BAKSET_CHECK( device_type varchar, bakset_pathvarchar(256) )
參數說明:
device_type:設備類型,disk或tape。
bakset_path:待校驗的備份集目錄。
返回值:
1:備份集目錄存在且合法;否則報錯。
舉例說明:
SQL> backup database full to db_rac_bak_for_check backupset '/dm7/backup/db_rac_bak_for_check'; executed successfully used time: 00:00:01.410. Execute id is 158. SQL> select sf_bakset_check('disk','/dm7/backup/db_rac_bak_for_check'); LINEID SF_BAKSET_CHECK('disk','/dm7/backup/db_rac_bak_for_check') ---------- ---------------------------------------------------------- 1 1 used time: 12.669(ms). Execute id is 159. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak_for_check'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak_for_check') ---------- ------------------------------------------------------------------- 1 1 used time: 1.610(ms). Execute id is 162. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- -------------------------------- 1 /dm7/backup/db_rac_bak_for_check 2 +DMDATA/data/rac/bak used time: 0.770(ms). Execute id is 163. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- -------------------- -------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 53418202 -1 DB_RAC_BAK_FOR_CHECK /dm7/backup/db_rac_bak_for_check 0 0 1 rac -1 2020-05-29 21:14:50.000773 0 0 0 0 33554432 50908 51113 2 4 1 0 0 49398 117507596 0 used time: 00:00:01.023. Execute id is 164.
SF_BAKSET_REMOVE函數
刪除指定設備類型和指定備份集目錄的備份集。一次只檢查一個合法.meta文件,然后刪除對應備份集;若存在非法或非正常備份的.meta文件,則報錯或直接返回,不會接著檢查下一個.meta文件;若同一個備份集下還存在其它備份文件或備份集,則只刪除備份文件,不會刪除整個備份集。
定義:
INT SF_BAKSET_REMOVE ( device_type varchar, backsetpath varchar(256), option integer )
參數說明:
device_type:設備類型,disk或tape。
backsetpath:待刪除的備份集目錄。
Option:刪除備份集選項,0默認刪除,1級聯刪除。可選參數。并行備份集中子備份集不允許單獨刪除。目標備份集被其他備份集引用為基備份的,默認刪除,報錯;級聯刪除情況下,會遞歸將相關的增量備份也刪除。
返回值:
1:備份集目錄刪除成功,其它情況下報錯。
舉例說明:
SQL> backup database full to db_rac_bak_for_remove backupset '/dm7/backup/db_rac_bak_for_remove'; executed successfully used time: 00:00:01.320. Execute id is 165. SQL> backup database increment base on backupset '/dm7/backup/db_rac_bak_for_remove' backupset '/dm7/backup/db_rac_bak_for_remove_incr'; executed successfully used time: 00:00:01.255. Execute id is 170. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak_for_remove'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak_for_remove') ---------- -------------------------------------------------------------------- 1 1 used time: 1.836(ms). Execute id is 171. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak_for_remove_incr'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak_for_remove_incr') ---------- ------------------------------------------------------------------------- 1 1 used time: 1.444(ms). Execute id is 172. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ---------------------------------- -------------------------------------- ----------- ----------- ----------- ----------- ----------- --------------------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 53418202 -1 DB_RAC_BAK_FOR_CHECK /dm7/backup/db_rac_bak_for_check 0 0 1 rac -1 2020-05-29 21:14:50.000773 0 0 0 0 33554432 50908 51113 2 4 1 0 0 49398 117507596 0 2 DISK 1763138770 -1 DB_RAC_BAK_FOR_REMOVE /dm7/backup/db_rac_bak_for_remove 0 0 1 rac -1 2020-05-29 22:00:34.000524 0 0 0 0 33554432 50908 51119 2 4 1 0 0 49398 117507596 0 3 DISK -1036285990 -1 DB_INCR_rac_20200529_220232_000624 /dm7/backup/db_rac_bak_for_remove_incr 1 0 1 rac -1 DB_RAC_BAK_FOR_REMOVE 2020-05-29 22:02:33.000834 0 0 0 0 33554432 50908 51135 2 4 1 0 0 49398 117507596 0 used time: 00:00:01.038. Execute id is 173. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- -------------------------------------- 1 /dm7/backup/db_rac_bak_for_check 2 /dm7/backup/db_rac_bak_for_remove 3 /dm7/backup/db_rac_bak_for_remove_incr 4 +DMDATA/data/rac/bak used time: 0.781(ms). Execute id is 174. SQL> select sf_bakset_remove('disk','/dm7/backup/db_rac_bak_for_remove'); select sf_bakset_remove('disk','/dm7/backup/db_rac_bak_for_remove'); [-8202]:Be the base backupset of /dm7/backup/db_rac_bak_for_remove_incr,cannot be removed. used time: 00:00:01.023. Execute id is 0.
報錯了,提示說它是另一個備份集的基備份不能被刪除
SQL> select sf_bakset_remove('disk','/dm7/backup/db_rac_bak_for_remove',1); LINEID SF_BAKSET_REMOVE('disk','/dm7/backup/db_rac_bak_for_remove',1) ---------- -------------------------------------------------------------- 1 1 used time: 50.201(ms). Execute id is 176.
檢查備份集可以確認在刪除基備份時確實級聯刪除了增量備份
SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- -------------------- -------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 53418202 -1 DB_RAC_BAK_FOR_CHECK /dm7/backup/db_rac_bak_for_check 0 0 1 rac -1 2020-05-29 21:14:50.000773 0 0 0 0 33554432 50908 51113 2 4 1 0 0 49398 117507596 0 used time: 00:00:01.050. Execute id is 177.
SF_BAKSET_REMOVE_BATCH函數
批量刪除滿足指定條件的所有備份集。
定義:
INT SF_BAKSET_REMOVE_BATCH ( device_type varchar, end_time datetime, range int, obj_name varchar(257) )
參數說明:
device_type:設備類型,disk或tape。指定NULL,則忽略存儲設備的區分。
end_time:刪除備份集生成的結束時間,僅刪除end_time之前的備份集,必須指定。
range:指定刪除備份的級別。1代表庫級,2代表表空間級,3代表表級,4代表歸檔備份。若指定NULL,則忽略備份集備份級別的區分。
obj_name:待刪除備份集中備份對象的名稱,僅表空間級和表級有效。若為表級備份刪除,則需指定完整的表名(模式.表名),否則,將認為刪除會話當前模式下的表備份。若指定為NULL,則忽略備份集中備份對象名稱區分
返回值:
1:備份集目錄刪除成功,其它情況下報錯。
舉例說明:
SQL> backup database full to db_rac_full_bak_for_remove backupset '/dm7/backup/db_rac_full_bak_for_remove'; executed successfully used time: 00:00:01.498. Execute id is 184. SQL> backup tablespace main full to tab_main_full_bak_for_remove backupset '/dm7/backup/tab_main_full_bak_for_remove'; executed successfully used time: 00:00:01.121. Execute id is 185. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_full_bak_for_remove'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_full_bak_for_remove') ---------- ------------------------------------------------------------------------- 1 1 used time: 1.574(ms). Execute id is 186. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/tab_main_full_bak_for_remove'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/tab_main_full_bak_for_remove') ---------- --------------------------------------------------------------------------- 1 1 used time: 1.881(ms). Execute id is 187. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ---------------------------------------- 1 /dm7/backup/db_rac_full_bak_for_remove 2 /dm7/backup/tab_main_full_bak_for_remove 3 +DMDATA/data/rac/bak used time: 0.784(ms). Execute id is 188. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ---------------------------- ---------------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 760083173 -1 DB_RAC_FULL_BAK_FOR_REMOVE /dm7/backup/db_rac_full_bak_for_remove 0 0 1 rac -1 2020-05-30 10:21:23.000661 0 0 0 0 33554432 50908 51141 2 4 1 0 0 49398 117507596 0 2 DISK -1117064059 -1 TAB_MAIN_FULL_BAK_FOR_REMOVE /dm7/backup/tab_main_full_bak_for_remove 0 0 2 MAIN 4 2020-05-30 10:22:41.000744 0 0 0 0 33554432 50908 51147 1 1 1 0 0 49398 117507596 0 used time: 00:00:01.025. Execute id is 189. SQL> select sf_bakset_remove_batch('disk',now(),null,null); LINEID SF_BAKSET_REMOVE_BATCH('disk',NOW(),NULL,NULL) ---------- ---------------------------------------------- 1 1 used time: 21.228(ms). Execute id is 190. SQL> select * from v$backupset; no rows used time: 00:00:01.023. Execute id is 191.
SP_DB_BAKSET_REMOVE_BATCH過程
批量刪除指定時間之前的數據庫備份集。使用該方法前,需要先使用SF_BAKSET_BACKUP_DIR_ADD添加將要刪除的備份集目錄,否則只刪除默
認備份路徑下的備份集。
定義:
SP_DB_BAKSET_REMOVE_BATCH ( device_type varchar, end_time datetime )
參數說明:
device_type:設備類型,disk或tape。指定NULL,則忽略存儲設備的區分。
end_time:刪除備份集生成的結束時間,僅刪除end_time之前的備份集,必須指定。
舉例說明:
SQL> backup database full to db_rac_full_bak_for_del backupset '/dm7/backup/db_rac_full_bak_for_del'; executed successfully used time: 00:00:01.580. Execute id is 194. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_full_bak_for_del'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_full_bak_for_del') ---------- ---------------------------------------------------------------------- 1 1 used time: 1.725(ms). Execute id is 195. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ----------------------------------- 1 /dm7/backup/db_rac_full_bak_for_del 2 +DMDATA/data/rac/bak used time: 0.483(ms). Execute id is 196. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ----------------------- ----------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 361744824 -1 DB_RAC_FULL_BAK_FOR_DEL /dm7/backup/db_rac_full_bak_for_del 0 0 1 rac -1 2020-05-30 10:27:00.000621 0 0 0 0 33554432 50908 51153 2 4 1 0 0 49398 117507596 0 used time: 00:00:01.024. Execute id is 197. SQL> call sp_db_bakset_remove_batch('disk',now()); DMSQL executed successfully used time: 36.535(ms). Execute id is 198. SQL> select * from v$backupset; no rows used time: 00:00:01.021. Execute id is 199.
SP_TS_BAKSET_REMOVE_BATCH過程
批量刪除指定表空間對象及指定時間之前的表空間備份集。使用該方法前,需要先使用SF_BAKSET_BACKUP_DIR_ADD添加將要刪除的備份集目錄,否則只刪除默認備份路徑下的備份集。
定義:
SP_TS_BAKSET_REMOVE_BATCH ( device_type varchar, end_time datetime, ts_name varchar(128) )
參數說明:
device_type:設備類型,disk或tape。指定NULL,則忽略存儲設備的區分。
end_time:刪除備份集生成的結束時間,僅刪除end_time之前的備份集,必須指定。
ts_name:表空間名,若未指定,則認為刪除所有滿足條件的表空間備份集。
舉例說明:
SQL> backup tablespace main full to tab_main_bak_full_for_del backupset '/dm7/backup/tab_main_bak_full_for_del'; executed successfully used time: 00:00:01.123. Execute id is 202. SQL> sf_bakset_backup_dir_add('disk','/dm7/backup/tab_main_bak_full_for_del'); DMSQL executed successfully used time: 1.256(ms). Execute id is 203. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ------------------------------------- 1 /dm7/backup/tab_main_bak_full_for_del 2 +DMDATA/data/rac/bak used time: 0.773(ms). Execute id is 204. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ------------------------- ------------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 798489856 -1 TAB_MAIN_BAK_FULL_FOR_DEL /dm7/backup/tab_main_bak_full_for_del 0 0 2 MAIN 4 2020-05-30 10:38:29.000350 0 0 0 0 33554432 50908 51159 1 1 1 0 0 49398 117507596 0 used time: 00:00:01.027. Execute id is 205. SQL> call sp_ts_bakset_remove_batch('disk',now(),'main'); DMSQL executed successfully used time: 16.765(ms). Execute id is 206. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ------------------------- ------------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 798489856 -1 TAB_MAIN_BAK_FULL_FOR_DEL /dm7/backup/tab_main_bak_full_for_del 0 0 2 MAIN 4 2020-05-30 10:38:29.000350 0 0 0 0 33554432 50908 51159 1 1 1 0 0 49398 117507596 0 used time: 00:00:01.022. Execute id is 207.
說明指定表空間名時表空間名要大寫
SQL> call sp_ts_bakset_remove_batch('disk',now(),'MAIN'); DMSQL executed successfully used time: 13.667(ms). Execute id is 208. SQL> select * from v$backupset; no rows used time: 00:00:01.023. Execute id is 209.
刪除備份目錄
SQL> sf_bakset_backup_dir_remove_all(); DMSQL executed successfully used time: 0.787(ms). Execute id is 210. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- -------------------- 1 +DMDATA/data/rac/bak used time: 0.836(ms). Execute id is 211.
SP_TAB_BAKSET_REMOVE_BATCH過程
批量刪除指定表對象及指定時間之前的表備份集。使用該方法前,需要先使用SF_BAKSET_BACKUP_DIR_ADD添加將要刪除的備份集目錄,否則只刪除默認備份路徑下的備份集。
定義:
SP_TAB_BAKSET_REMOVE_BATCH ( device_type varchar, end_time datetime, sch_name varchar(128), tab_name varchar(128) ) 參數說明: device_type:設備類型,disk或tape。指定NULL,則忽略存儲設備的區分。 end_time:刪除備份集生成的結束時間,僅刪除end_time之前的備份集,必須指定。 sch_name:表所屬的模式名。 tab_name:表名,只要模式名和表名有一個指定,就認為需要匹配目標;若均指定為NULL,則認為刪除滿足條件的所有表備份。 舉例說明:
SQL> create table tab_for_del_batch(c1 int); executed successfully used time: 18.840(ms). Execute id is 212. SQL> insert into tab_for_del_batch values(1); affect rows 1 used time: 1.840(ms). Execute id is 213. SQL> commit; executed successfully used time: 1.557(ms). Execute id is 214. SQL> backup table tab_for_del_batch to tab_bak_for_del_batch backupset '/dm7/backup/tab_bak_for_del_batch'; executed successfully used time: 00:00:01.142. Execute id is 215. SQL> call sf_bakset_backup_dir_add('disk','/dm7/backup/tab_bak_for_del_batch'); DMSQL executed successfully used time: 1.436(ms). Execute id is 216. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- --------------------------------- 1 /dm7/backup/tab_bak_for_del_batch 2 +DMDATA/data/rac/bak used time: 0.742(ms). Execute id is 217. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- --------------------- --------------------------------- ----------- ----------- ----------- ------------------------ ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK -424456112 -1 TAB_BAK_FOR_DEL_BATCH /dm7/backup/tab_bak_for_del_batch 2 0 3 SYSDBA.TAB_FOR_DEL_BATCH -1 2020-05-30 11:07:05.000089 0 0 0 0 33554432 50908 51200 1 0 1 0 0 49398 117507596 0 used time: 00:00:01.023. Execute id is 218. SQL> sp_tab_bakset_remove_batch('disk',now(),'SYSDBA','TAB_FOR_DEL_BATCH'); DMSQL executed successfully used time: 14.860(ms). Execute id is 219. SQL> select * from v$backupset; no rows used time: 00:00:01.022. Execute id is 220. SQL> sf_bakset_backup_dir_remove_all(); DMSQL executed successfully used time: 0.955(ms). Execute id is 221. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- -------------------- 1 +DMDATA/data/rac/bak used time: 1.138(ms). Execute id is 222.
SP_ARCH_BAKSET_REMOVE_BATCH過程
批量刪除指定時間之前的歸檔備份集。使用該方法前,需要先使用SF_BAKSET_BACKUP_DIR_ADD添加將要刪除的備份集目錄,否則只刪除默認備份路徑下的備份集。
定義:
SP_ARCH_BAKSET_REMOVE_BATCH ( device_type varchar, end_time datetime )
參數說明:
device_type:設備類型,disk或tape。指定NULL,則忽略存儲設備的區分。
end_time:刪除備份集生成的結束時間,僅刪除end_time之前的備份集,必須指定。
舉例說明:
SQL> backup archivelog to arch_bak_for_del_batch backupset '/dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_for_del_batch'; executed successfully used time: 00:00:36.170. Execute id is 2476. SQL> sf_bakset_backup_dir_add('disk','/dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_for_del_batch'); DMSQL executed successfully used time: 0.768(ms). Execute id is 2478. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ---------------------------------------------------------- 1 /dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_for_del_batch 2 /dm_home/dmdba/dmdbms/data/jydm/bak used time: 0.568(ms). Execute id is 2479. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ---------------------- ---------------------------------------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 1259288472 -1 ARCH_BAK_FOR_DEL_BATCH /dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_for_del_batch 3 0 4 ARCHIVE -1 2020-05-30 14:29:32.000827 0 0 1 0 33554432 8236220 15220690 1 12 1 0 0 15220690 117507596 0 2 DISK 1259288472 -1 ARCH_BAK_FOR_DEL_BATCH /dm_home/dmdba/dmdbms/data/jydm/bak/arch_bak_for_del_batch 3 0 4 ARCHIVE -1 2020-05-30 14:29:32.000827 0 0 1 0 33554432 8236220 15220690 1 12 1 0 0 15220690 117507596 0 used time: 00:00:01.023. Execute id is 2480. SQL> sp_arch_bakset_remove_batch('disk',now()); DMSQL executed successfully used time: 178.477(ms). Execute id is 2485. SQL> select * from v$backupset; no rows used time: 00:00:01.009. Execute id is 2486. SQL> sf_bakset_backup_dir_remove_all(); DMSQL executed successfully used time: 0.826(ms). Execute id is 2492. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ----------------------------------- 1 /dm_home/dmdba/dmdbms/data/jydm/bak used time: 0.763(ms). Execute id is 2493.
4. 備份信息查看
DM7提供了一系列動態視圖供用戶查看備份集相關信息,在查看之前應先使用SF_BAKSET_BACKUP_DIR_ADD添加備份集目錄,否則只顯示默認備份路徑下的備份集信息,使用方法如下例所示:
SQL>SELECT SF_BAKSET_BACKUP_DIR_ADD('DISK', '/home/dm_bak');
下面逐個介紹DM7提供的備份相關動態視圖。
V$BACKUPSET顯示備份集基本信息。
SQL> desc v$backupset LINEID NAME TYPE$ NULLABLE ---------- ----------------- ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUP_ID INTEGER Y 備份ID 3 PARENT_ID INTEGER Y 并行備份的子備份集所屬備份的ID 4 BACKUP_NAME VARCHAR(512) Y 備份名 5 BACKUP_PATH VARCHAR(1024) Y 備份路徑 6 TYPE INTEGER Y 0:基備份,1:增量備份,2:表備份,3:歸檔備份 7 LEVEL INTEGER Y 是否脫機備份。0:聯機備份,1:脫機備份 8 RANGE# INTEGER Y 1:庫備份,2:表空間備份,3:表級備份,4:歸檔備份 9 OBJECT_NAME VARCHAR(1025) Y 對象名:數據庫名、表空間名或者表名 10 OBJECT_ID INTEGER Y 對象ID,表備份時無效 11 BASE_NAME VARCHAR(512) Y 基備份名,表備份時無效 12 BACKUP_TIME DATETIME(6) Y 備份時間 13 DESC# VARCHAR(1024) Y 備份描述信息 14 ENCRYPT_TYPE INTEGER Y 加密類型 15 COMPRESS_LEVEL INTEGER Y 壓縮級別 16 WITHOUT_LOG INTEGER Y 聯機數據庫備份是否備份日志,表備份時無效 17 USE_PWR INTEGER Y 增量備份過程中是否使用PWR優化,均不使用,保留僅為了兼容 18 PKG_SIZE INTEGER Y 數據包大寫標志,內部實現 19 BEGIN_LSN BIGINT Y 備份的起始LSN值,表備份時無效 20 END_LSN BIGINT Y 結束備份的LSN值,表備份時無效 21 BKP_NUM INTEGER Y 備份片個數,即備份集中.bak文件個數 22 DBF_NUM INTEGER Y 備份集中包含的數據庫\表空間數據文件個數,表備份時無效 23 PARALLEL_NUM INTEGER Y 并行備份的并行數,0或者1為非并行備份集 24 DDL_CLONE INTEGER Y DDL_CLONE庫備份標識,0不是,1是 25 MPP_FLAG INTEGER Y MPP庫備份標識,0不是,1是 26 MIN_TRX_START_LSN BIGINT Y 備份時活動事務最小的LSN 27 MIN_EXEC_VER INTEGER Y 備份集適用的最小執行碼的版本號,轉換為16進制匹配版本號 28 CUMULATIVE INTEGER Y 增量備份時,是否為累積增量備份。1是,0否
下面以創建數據庫備份為例,查看備份集的介質類型、備份路徑、備份類型等基本信息:
SQL> backup database full to db_rac_bak_for_info backupset '/dm7/backup/db_rac_bak_for_info'; executed successfully used time: 00:00:01.298. Execute id is 224. SQL> sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak_for_info'); DMSQL executed successfully used time: 0.939(ms). Execute id is 225. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ------------------------------- 1 /dm7/backup/db_rac_bak_for_info 2 +DMDATA/data/rac/bak used time: 1.726(ms). Execute id is 226. SQL> select device_type,backup_path,type,range# from v$backupset; LINEID DEVICE_TYPE BACKUP_PATH TYPE RANGE# ---------- ----------- ------------------------------- ----------- ----------- 1 DISK /dm7/backup/db_rac_bak_for_info 0 1 used time: 00:00:01.023. Execute id is 227.
V$BACKUPSET_DBINFO顯示備份集的數據庫相關信息。
SQL> desc v$backupset_dbinfo; LINEID NAME TYPE$ NULLABLE ---------- -------------- ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUP_ID INTEGER Y 備份ID 3 BACKUP_NAME VARCHAR(512) Y 備份名 4 BACKUP_PATH VARCHAR(1024) Y 備份路徑 5 EXTENT_SIZE INTEGER Y 數據文件使用的簇大小 6 PAGE_SIZE INTEGER Y 頁大小 7 LOG_PAGE_SIZE INTEGER Y 日志文件頁大小 8 CASE_SENSITVE INTEGER Y 大小寫敏感標志 9 DB_MAGIC INTEGER Y 數據庫的magic 10 PM_DB_MAGIC INTEGER Y 永久魔數(permenant_magic) 11 UNICODE_FLAG INTEGER Y unicode標志 12 DB_VERSION INTEGER Y 數據庫版本 13 GLOBAL_VERSION VARCHAR(512) Y 數據庫全局版本信息 14 ENABLE_POLICY INTEGER Y 安全策略 15 ARCH_FLAG INTEGER Y 歸檔是否打開的標志 16 RAC_NODE INTEGER Y 高性能集群的節點數目 17 PAGE_CHECK INTEGER Y 數據頁校驗配置 18 RLOG_ENCRYPT INTEGER Y 歸檔日志是否加密 19 EX_CIPHER_NAME VARCHAR(512) Y 外部加密算法名稱 20 EX_CIPHER_ID INTEGER Y 外部加密算法名稱對應的ID 21 EX_HASH_NAME VARCHAR(512) Y 外部HASH算法名稱 22 EX_HASH_ID INTEGER Y 外部HASH算法名稱對應的ID 23 LENGTH_IN_CHAR INTEGER Y VARCHAR類型長度是否以字符為單位 24 USE_NEW_HASH INTEGER Y 是否使用改進的字符類型HASH算法 25 BLANK_PAD_MODE INTEGER Y 數據庫空格填充模式
表還原時要求目標庫的特定建庫參數要與源庫一致,如頁大小、簇大小,通過查看備份文件的數據庫信息可確定目標庫需要設置哪些建庫參數。下面以創建表備份為例,查看備份集的頁大小、簇大小、大小寫是否敏感、UNICODE_FLAG等數據庫信息:
SQL> backup table tab_01 to tab_01_bak backupset '/dm7/backup/tab_01_bak'; executed successfully used time: 00:00:01.119. Execute id is 236. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/tab_01_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/tab_01_bak') ---------- --------------------------------------------------------- 1 1 used time: 2.096(ms). Execute id is 237. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ---------------------- 1 /dm7/backup/tab_01_bak 2 +DMDATA/data/rac/bak used time: 0.726(ms). Execute id is 238. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ----------- ---------------------- ----------- ----------- ----------- ------------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 1132430805 -1 TAB_01_BAK /dm7/backup/tab_01_bak 2 0 3 SYSDBA.TAB_01 -1 2020-05-30 14:56:59.000255 0 0 0 0 33554432 50908 51208 1 0 1 0 0 49398 117507596 0 used time: 00:00:01.023. Execute id is 239. SQL> select backup_path,page_size,extent_size,case_sensitive from v$backupset_dbinfo where backup_path='/dm7/backup/tab_01_bak'; LINEID BACKUP_PATH PAGE_SIZE EXTENT_SIZE CASE_SENSITIVE ---------- ---------------------- ----------- ----------- -------------- 1 /dm7/backup/tab_01_bak 8192 16 1 used time: 00:00:01.028. Execute id is 240.
V$BACKUPSET_DBF顯示備份集中數據文件的相關信息,表備份時無效。
SQL> desc v$backupset_dbf LINEID NAME TYPE$ NULLABLE ---------- -------------- ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUP_ID INTEGER Y 備份ID 3 BACKUPNAME VARCHAR(512) Y 備份名 4 BACKUPPATH VARCHAR(1024) Y 備份路徑 5 FILE_SEQ INTEGER Y 備份的數據文件序號 6 TS_ID INTEGER Y 表空間ID 7 FILE_ID INTEGER Y 數據文件ID 8 TS_STATE INTEGER Y 表空間狀態 9 TS_NAME VARCHAR(512) Y 表空間名 10 FILE_NAME VARCHAR(1024) Y 包含完整路徑的數據文件名 11 MIRROR_PATH VARCHAR(1024) Y 鏡像文件路徑 12 FILE_LEN BIGINT Y 數據文件占用的字節大小 13 MAX_LIMIT_SIZE INTEGER Y 文件最大大小,以M為單位 14 AUTO_EXTEND INTEGER Y 是否支持自動擴展:1支持,0不支持 15 NEXT_SIZE INTEGER Y 文件每次擴展大小,以M為單位 16 START_BKP_SEQ INTEGER Y 起始備份片編號 17 START_BKP_OFF BIGINT Y 起始備份片偏移 18 END_BKP_SEQ INTEGER Y 結束備份片編號 19 END_BKP_OFF BIGINT Y 結束備份片偏移
數據庫和表空間備份集中記錄了備份的數據文件具體信息,如果想了解備份集中包含了哪些數據文件且這些數據文件有什么屬性,可通過查詢V$BACKUPSET_DBF實現。下面以表空間備份為例,查看備份集中的數據文件信息。
SQL> create tablespace ts_for_dbf datafile 'ts_for_dbf_01.dbf' size 128; executed successfully used time: 00:00:01.594. Execute id is 247. SQL> alter tablespace ts_for_dbf add datafile 'ts_for_dbf_02.dbf' size 128; executed successfully used time: 236.359(ms). Execute id is 248. SQL> select * from v$datafile; LINEID GROUP_ID ID PATH CLIENT_PATH CREATE_TIME STATUS$ RW_STATUS LAST_CKPT_TIME MODIFY_TIME MODIFY_TRX TOTAL_SIZE FREE_SIZE FREE_PAGE_NO PAGES_READ PAGES_WRITE PAGE_SIZE READ_REQUEST WRITE_REQUEST AUTO_EXTEND MAX_SIZE NEXT_SIZE MIRROR_PATH ---------- ----------- ----------- ---------------------------------- ----------------- --------------------------- ----------- ----------- --------------------------- --------------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- ----------- ------------ ------------- ----------- ----------- ----------- ----------- 1 0 0 +DMDATA/data/rac/system.dbf system.dbf 2020-04-26 15:44:40 1 2 2020-05-30 15:06:01 2020-04-26 15:44:40 8326 16384 15760 1520 248 50 8192 248 50 1 16777215 0 NULL 2 1 0 +DMDATA/data/rac/roll.dbf roll.dbf 2020-04-26 15:44:40 1 2 2020-05-30 15:06:01 2020-04-26 15:44:40 8326 16384 13780 2624 1303 5209 8192 1303 5209 1 16777215 0 NULL 3 3 0 +DMDATA/data/rac/TEMP0.DBF TEMP0.DBF 2020-05-28 16:52:15 1 2 2020-05-30 15:06:01 2020-05-28 16:52:15 8326 1280 1270 32 0 0 8192 0 0 1 16777215 0 NULL 4 4 0 +DMDATA/data/rac/main.dbf main.dbf 2020-04-26 15:44:43 1 2 2020-05-30 15:06:01 2020-04-26 15:44:43 8326 16384 16369 64 4 10 8192 4 10 1 16777215 0 NULL 5 5 0 +DMDATA/data/rac/ts_for_dbf_01.dbf ts_for_dbf_01.dbf 2020-05-30 15:06:00 1 2 2020-05-30 15:06:01 2020-05-30 15:06:00 8326 16384 16376 32 0 1 8192 0 1 1 16777215 0 NULL 6 5 1 +DMDATA/data/rac/ts_for_dbf_02.dbf ts_for_dbf_02.dbf 2020-05-30 15:06:29 1 2 2020-05-30 15:06:01 2020-05-30 15:06:29 8326 16384 16383 32 0 0 8192 0 0 1 16777215 0 NULL 6 rows got used time: 5.737(ms). Execute id is 249. SQL> backup tablespace ts_for_dbf to ts_for_dbf_bak backupset '/dm7/backup/ts_for_dbf_bak'; executed successfully used time: 00:00:01.114. Execute id is 250. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/ts_for_dbf_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/ts_for_dbf_bak') ---------- ------------------------------------------------------------- 1 1 used time: 1.928(ms). Execute id is 251. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- -------------------------- 1 /dm7/backup/ts_for_dbf_bak 2 +DMDATA/data/rac/bak used time: 0.848(ms). Execute id is 252. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- -------------- -------------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 1346953844 -1 TS_FOR_DBF_BAK /dm7/backup/ts_for_dbf_bak 0 0 2 TS_FOR_DBF 5 2020-05-30 15:08:17.000425 0 0 0 0 33554432 51236 51238 1 2 1 0 0 49398 117507596 0 used time: 00:00:01.023. Execute id is 253. SQL> select file_seq,ts_id,file_id,ts_name,file_name from v$backupset_dbf; LINEID FILE_SEQ TS_ID FILE_ID TS_NAME FILE_NAME ---------- ----------- ----------- ----------- ---------- ---------------------------------- 1 1 5 0 TS_FOR_DBF +DMDATA/data/rac/ts_for_dbf_01.dbf 2 2 5 1 TS_FOR_DBF +DMDATA/data/rac/ts_for_dbf_02.dbf used time: 00:00:01.023. Execute id is 254.
V$BACKUPSET_ARCH顯示備份集中歸檔文件的信息,且僅歸檔備份才會有數據。
SQL> desc v$backupset_arch LINEID NAME TYPE$ NULLABLE ---------- -------------- ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUP_ID INTEGER Y 備份ID 3 BACKUPNAME VARCHAR(512) Y 備份名 4 BACKUPPATH VARCHAR(1024) Y 備份路徑 5 FILE_SEQ INTEGER Y 備份的數據文件序號 6 FILE_NAME VARCHAR(1024) Y 歸檔文件路徑 7 FILE_LEN BIGINT Y 歸檔文件大小 8 BEGIN_LSN BIGINT Y 備份歸檔的起始LSN值 9 BEGIN_SEQNO BIGINT Y 起始備份歸檔序號 10 BEGIN_RPAG_OFF INTEGER Y 備份歸檔起始LSN對應歸檔頁內偏移 11 END_LSN BIGINT Y 結束備份歸檔的LSN值 12 CREATE_TIME DATETIME(6) Y 歸檔文件的創建時間 13 CLOSE_TIME DATETIME(6) Y 歸檔文件的關閉時間 14 START_BKP_SEQ INTEGER Y 起始備份片編號 15 START_BKP_OFF BIGINT Y 起始備份片偏移 16 END_BKP_SEQ INTEGER Y 結束備份片編號 17 END_BKP_OFF BIGINT Y 結束備份片偏移
備份集日志信息可以是聯機庫備份備份開始到備份結束這段時間服務器產生的日志,也可以是歸檔備份中備份的歸檔信息。接下來以數據庫備份為例查詢備份集日志信息。
SQL> backup database to db_rac_bak backupset '/dm7/backup/db_rac_bak'; executed successfully used time: 00:00:01.451. Execute id is 259. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak') ---------- --------------------------------------------------------- 1 1 used time: 1.664(ms). Execute id is 260. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ---------------------- 1 /dm7/backup/db_rac_bak 2 +DMDATA/data/rac/bak used time: 0.775(ms). Execute id is 261. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ----------- ---------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK -274484992 -1 DB_RAC_BAK /dm7/backup/db_rac_bak 0 0 1 rac -1 2020-05-30 15:16:49.000122 0 0 0 0 33554432 51236 51244 2 6 1 0 0 49398 117507596 0 used time: 00:00:01.020. Execute id is 262. SQL> select backuppath,file_seq,file_name,begin_lsn,end_lsn from v$backupset_arch where backuppath='/dm7/backup/db_rac_bak'; LINEID BACKUPPATH FILE_SEQ FILE_NAME BEGIN_LSN END_LSN ---------- ---------------------- ----------- --------- -------------------- -------------------- 1 /dm7/backup/db_rac_bak 6 51241 51244 used time: 00:00:01.025. Execute id is 263.
V$BACKUPSET_BKP顯示備份集的備份片信息。
SQL> desc v$backupset_bkp LINEID NAME TYPE$ NULLABLE ---------- ----------- ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUP_ID INTEGER Y 備份ID 3 BACKUPNAME VARCHAR(512) Y 備份名 4 BACKUPPATH VARCHAR(1024) Y 備份路徑 5 BKP_NTH INTEGER Y 備份片文件編號 6 FILE_NAME VARCHAR(1024) Y 備份文件名 7 BKP_LEN BIGINT Y 備份片長度
以數據庫備份為例,查看備份集中的備份片信息。
SQL> backup database to db_rac_bak backupset '/dm7/backup/db_rac_bak'; executed successfully used time: 00:00:01.451. Execute id is 259. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak') ---------- --------------------------------------------------------- 1 1 used time: 1.664(ms). Execute id is 260. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ---------------------- 1 /dm7/backup/db_rac_bak 2 +DMDATA/data/rac/bak used time: 0.775(ms). Execute id is 261. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ----------- ---------------------- ----------- ----------- ----------- ----------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK -274484992 -1 DB_RAC_BAK /dm7/backup/db_rac_bak 0 0 1 rac -1 2020-05-30 15:16:49.000122 0 0 0 0 33554432 51236 51244 2 6 1 0 0 49398 117507596 0 used time: 00:00:01.020. Execute id is 262. SQL> select backuppath,bkp_nth,file_name,bkp_len from v$backupset_bkp where backuppath='/dm7/backup/db_rac_bak'; LINEID BACKUPPATH BKP_NTH FILE_NAME BKP_LEN ---------- ---------------------- ----------- ---------------- -------------------- 1 /dm7/backup/db_rac_bak 0 db_rac_bak.bak 26688000 2 /dm7/backup/db_rac_bak 1 db_rac_bak_1.bak 6144 used time: 00:00:01.025. Execute id is 265.
V$BACKUPSET_SEARCH_DIRS顯示備份集搜索目錄。
SQL> desc v$backupset_search_dirs LINEID NAME TYPE$ NULLABLE ---------- ---- ------------- -------- 1 DIR VARCHAR(1024) Y 備份集搜索目錄
查詢V$BACKUPSET_SEARCH_DIRS顯示當前會話已添加的備份目錄,即備份集搜索目錄。若用戶沒有添加備份目錄,那么僅顯示默認的備份目錄。
SQL> select sf_bakset_backup_dir_remove_all(); LINEID SF_BAKSET_BACKUP_DIR_REMOVE_ALL() ---------- --------------------------------- 1 1 used time: 0.882(ms). Execute id is 267. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- -------------------- 1 +DMDATA/data/rac/bak used time: 0.965(ms). Execute id is 268.
如果添加備份目錄,查詢結果包括默認備份目錄和用戶添加的備份目錄。
SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak') ---------- --------------------------------------------------------- 1 1 used time: 0.894(ms). Execute id is 269. SQL> select * from v$backupset_search_dirs; LINEID DIR ---------- ---------------------- 1 /dm7/backup/db_rac_bak 2 +DMDATA/data/rac/bak used time: 0.714(ms). Execute id is 270.
V$BACKUPSET_TABLE顯示表備份集中備份表信息,僅表備份有效。
SQL> desc v$backupset_table LINEID NAME TYPE$ NULLABLE ---------- ------------ ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUP_ID INTEGER Y 備份ID 3 BACKUPNAME VARCHAR(512) Y 備份名 4 BACKUPPATH VARCHAR(1024) Y 備份路徑 5 SCHEMANAME VARCHAR(512) Y 備份表所屬的模式名 6 USERNAME VARCHAR(512) Y 執行表備份的用戶名 7 TSNAME VARCHAR(512) Y 備份表存儲的表空間名 8 TABLENAME VARCHAR(512) Y 備份表名 9 TABLETYPE INTEGER Y 表類型 10 INIT_SQL VARCHAR(4096) Y 完整建表語句,忽略引用約束(語句可能會被截斷) 11 DCONS_SQL VARCHAR(4096) Y 備份表中被禁用約束的創建語句(語句可能會被截斷,DMRMAN可查看完整語句) 12 DIDX_SQL VARCHAR(4096) Y 備份表中無效二級索引的創建語句(語句可能會被截斷,DMRMAN可查看完整語句) 13 BIDX_NUM INTEGER Y 備份集中備份的二級索引個數 14 META_VERSION INTEGER Y 當前表備份的元信息的版本號
下面創建表備份并查看備份中備份名、備份路徑、表名等信息。
SQL> create table tab_for_info(c1 int); executed successfully used time: 12.459(ms). Execute id is 277. SQL> insert into tab_for_info values(1); affect rows 1 used time: 1.779(ms). Execute id is 278. SQL> commit; executed successfully used time: 1.775(ms). Execute id is 279. SQL> backup table tab_for_info to tab_for_info_bak backupset '/dm7/backup/tab_for_info_bak'; executed successfully used time: 00:00:01.133. Execute id is 280. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/tab_for_info_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/tab_for_info_bak') ---------- --------------------------------------------------------------- 1 1 used time: 1.250(ms). Execute id is 281. SQL> select * from v$backupset; LINEID DEVICE_TYPE BACKUP_ID PARENT_ID BACKUP_NAME BACKUP_PATH TYPE LEVEL RANGE# OBJECT_NAME OBJECT_ID BASE_NAME BACKUP_TIME DESC# ENCRYPT_TYPE COMPRESS_LEVEL WITHOUT_LOG USE_PWR PKG_SIZE BEGIN_LSN END_LSN BKP_NUM DBF_NUM PARALLEL_NUM DDL_CLONE MPP_FLAG MIN_TRX_START_LSN MIN_EXEC_VER CUMULATIVE ---------- ----------- ----------- ----------- ---------------- ---------------------------- ----------- ----------- ----------- ------------------- ----------- --------- --------------------------- ----- ------------ -------------- ----------- ----------- ----------- -------------------- -------------------- ----------- ----------- ------------ ----------- ----------- -------------------- ------------ ----------- 1 DISK 378752781 -1 TAB_FOR_INFO_BAK /dm7/backup/tab_for_info_bak 2 0 3 SYSDBA.TAB_FOR_INFO -1 2020-05-30 15:31:29.000827 0 0 0 0 33554432 51236 51284 1 0 1 0 0 49398 117507596 0 used time: 00:00:01.019. Execute id is 282. SQL> select backupname,tablename from v$backupset_table; LINEID BACKUPNAME TABLENAME ---------- ---------------- ------------ 1 TAB_FOR_INFO_BAK TAB_FOR_INFO used time: 00:00:01.018. Execute id is 283.
V$BACKUPSET_SUBS顯示并行備份中生成的子備份集信息
SQL> desc v$backupset_subs LINEID NAME TYPE$ NULLABLE ---------- ----------- ------------- -------- 1 DEVICE_TYPE VARCHAR(10) Y 備份集存儲介質類型 2 BACKUPNAME VARCHAR(512) Y 備份名 3 BACKUP_ID INTEGER Y 備份ID 4 PARENT_ID INTEGER Y 子備份集所屬主備份集ID 5 BACKUPPATH VARCHAR(1024) Y 各備份集絕對路徑 6 BKP_NUM INTEGER Y 各備份集中備份片文件個數,可能為0 7 DBF_NUM INTEGER Y 各備份集中備份數據文件個數,可能為0
數據庫和表空間支持并行備份,備份后會在主備份集中生成多個子備份集,查詢視圖V$BACKUPSET_SUBS可獲取子備份集中包含的備份片文件個數及備份數據文件個數等信息。以創建數據庫并行備份為例,查看子備份集的相關信息。
SQL> backup database full to db_rac_bak backupset '/dm7/backup/db_rac_bak' parallel 4; executed successfully used time: 00:00:05.766. Execute id is 304. SQL> select sf_bakset_backup_dir_add('disk','/dm7/backup/db_rac_bak'); LINEID SF_BAKSET_BACKUP_DIR_ADD('disk','/dm7/backup/db_rac_bak') ---------- --------------------------------------------------------- 1 1 used time: 0.918(ms). Execute id is 305. SQL> select backuppath,bkp_num,dbf_num from v$backupset_subs; LINEID BACKUPPATH BKP_NUM DBF_NUM ---------- ----------------------------------- ----------- ----------- 1 /dm7/backup/db_rac_bak/db_rac_bak_2 1 1 2 /dm7/backup/db_rac_bak/db_rac_bak_3 1 1 3 /dm7/backup/db_rac_bak/db_rac_bak_0 1 2 4 /dm7/backup/db_rac_bak/db_rac_bak_1 1 1 used time: 13.850(ms). Execute id is 306.
看完上述內容,你們對DM7中怎么利用disql管理備份有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。