DB2_建立備份恢復使用自動儲存的資料庫
目的:
測試DB2使用自動儲存資料庫的建立、備份、恢復,本指令碼摘錄自DB2安裝目錄admin_scripts/autostore.db2。
版本:Windows DB2 Express-C V9.7
使用者要求:
作業系統使用者mh有DBADM,SECADM許可權,mh1234
操作步驟:
在作業系統命令視窗set DB2TESTPATH=E:;然後,使用"db2cmd db2 -td@"進入互動模式,執行後續操作。
1,建立目錄
!mkdir "%DB2TESTPATH%\storpath1"@
!mkdir "%DB2TESTPATH%\storpath2"@
!mkdir "%DB2TESTPATH%\storpath3"@
!mkdir "%DB2TESTPATH%\storpath4"@
2,建立資料庫
-- Create a database enabled for automatic storage with two storage paths and
-- on a specified database path
-- The storage paths used are: %DB2TESTPATH%\storpath1, %DB2TESTPATH%\storpath2
-- The database path use is : %DB2TESTPATH%\dbpath
! db2 "CREATE DATABASE autodb AUTOMATIC STORAGE YES ON
\"%DB2TESTPATH%\storpath1\", \"%DB2TESTPATH%\storpath2\" DBPATH ON \"%DB2TESTPATH%\""@
3,建立資料庫物件
CONNECT TO autodb@
-- Create a tablespace enabled for automatic storage. If no MANAGED BY clause
-- is specified the tablespace is, by default, managed by automatic storage.
CREATE TABLESPACE TS1@
-- Create another tablespace enabled to auto-resize
-- TS2 is created with an initial size of 100 MB and with a maximum size of 1 GB
-- (By default AUTORESIZE is set to YES)
CREATE TABLESPACE TS2 INITIALSIZE 100 M MAXSIZE 1 G@
-- Create tablespace without auto-resize enabled
CREATE TABLESPACE TS3 AUTORESIZE NO@
-- Create tablespace enabled to auto-resize without any upper bound on
-- maximum size
CREATE TABLESPACE TS4
MANAGED BY DATABASE
USING (FILE 'TS3File' 1000)
AUTORESIZE YES
MAXSIZE NONE@
-- Alter tablespace to increase its size by 5 percent
ALTER TABLESPACE TS4 INCREASESIZE 5 PERCENT@
-- Alter database to add one more storage path, %DB2TESTPATH%\storpath3, to the
-- existing space for automatic storage table spaces
-- Running the ALTER DATABASE statement in a shell as path substitution
-- can be done inside a sheell
!db2 "CONNECT TO AUTODB"@
!db2 "ALTER DATABASE autodb ADD STORAGE ON '%DB2TESTPATH%\storpath3'"@
--測試直接執行ALTER DATABASE
ALTER DATABASE autodb ADD STORAGE ON '%DB2TESTPATH%\storpath4'@
SQL1051N 路徑 "%DB2TESTPATH%\storpath4" 不存在或無效。 SQLSTATE=57019
--測試直接執行ALTER DATABASE
ALTER DATABASE autodb ADD STORAGE ON %DB2TESTPATH%\storpath4@
SQL0007N "AGE ON %DB2TESTPATH%" 後面的字元 "\" 無效。 SQLSTATE=42601
!db2 "CONNECT TO AUTODB"@
!db2 "ALTER DATABASE autodb ADD STORAGE ON '%DB2TESTPATH%\storpath4'"@
connect to autodb@
create table t(x int)@
insert into t values 1,2,3@
commit@
create table t3(x int) in ts4@
insert into t3 values 1,2,3@
commit@
-- Check the status information of tablespaces for database AUTODB
GET SNAPSHOT FOR TABLESPACES ON autodb@
select * from syscat.tablespaces@
4,備份資料庫
-- Disconnect from database
!db2 "CONNECT RESET"@
-- Backup the database
BACKUP DATABASE autodb@
備份成功。此備份映像的時間戳記是:20110713144106
5,刪除資料庫
-- Connect to database
CONNECT TO autodb@
-- Drop the tablespaces
DROP TABLESPACE TS1@
DROP TABLESPACE TS2@
DROP TABLESPACE TS3@
DROP TABLESPACE TS4@
-- Disconnect from database
CONNECT RESET@
-- Drop the database
DROP DATABASE autodb@
6,恢復資料庫
-- Restore the database to a set of storage paths
! db2 "RESTORE DATABASE autodb ON \"%DB2TESTPATH%\storpath2\",
\"%DB2TESTPATH%\storpath3\" DBPATH ON \"%DB2TESTPATH%\" WITHOUT PROMPTING"@
SQL2522N 多個備份檔案與為備份的資料庫映像提供的時間戳記值相匹配。
! db2 "RESTORE DATABASE autodb taken at 20110713144106 ON \"%DB2TESTPATH%\storpath2\",
\"%DB2TESTPATH%\storpath3\" DBPATH ON \"%DB2TESTPATH%\" WITHOUT PROMPTING"@
DB20000I RESTORE DATABASE 命令成功完成。
connect to autodb@
select * from t@
X
-----------
1
2
3
3 條記錄已選擇。
select * from t3@
X
-----------
1
2
3
3 條記錄已選擇。
7,清理測試環境
-- Drop the database 'AUTODB'
force application all@
DROP DB AUTODB@
-- Remove the directories.
!rmdir "%DB2TESTPATH%\storpath1"@
!rmdir "%DB2TESTPATH%\storpath2"@
!rmdir "%DB2TESTPATH%\storpath3"@
!rmdir "%DB2TESTPATH%\storpath4"@
TERMINATE@
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/18922393/viewspace-702092/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 分散式文件儲存資料庫之MongoDB備份與恢復分散式資料庫MongoDB
- MySQL不同儲存引擎的資料備份與恢復MySql儲存引擎
- 備份與恢復:polardb資料庫備份與恢復資料庫
- 資料庫備份恢復資料庫
- 使用Mysqldump備份和恢復MySQL資料庫MySql資料庫
- PostgreSql資料庫的備份和恢復SQL資料庫
- SqlServer資料庫恢復備份資料的方法SQLServer資料庫
- Mysql資料庫備份及恢復MySql資料庫
- 達夢資料庫備份恢復資料庫
- postgresql備份與恢復資料庫SQL資料庫
- GitLab的自動備份、清理備份與恢復Gitlab
- 【儲存資料恢復】NetApp儲存誤刪除的資料恢復案例資料恢復APP
- 【儲存資料恢復】NetApp儲存誤刪資料夾的資料恢復案例資料恢復APP
- mysqldump使用方法(MySQL資料庫的備份與恢復)MySql資料庫
- 恢復MySQL資料庫建立儲存過程是遇到錯誤MySql資料庫儲存過程
- 資料庫備份與恢復技術資料庫
- Mongo 資料庫備份和恢復命令Go資料庫
- pg_dump 備份,恢復資料庫資料庫
- 【儲存資料恢復】EqualLogic PS系列儲存磁碟故障的資料恢復案例資料恢復
- 資料庫資料恢復—無備份,binlog未開啟的Mysql資料庫資料恢復案例資料庫資料恢復MySql
- Linux下MySQL資料庫的備份與恢復LinuxMySql資料庫
- 【儲存資料恢復】HP EVA儲存誤刪除VDISK的資料恢復案例資料恢復
- 誤刪除儲存SqlServer資料庫資料恢復SQLServer資料庫資料恢復
- 【VSAN資料恢復】VSAN儲存資料恢復案例資料恢復
- mongodb資料庫備份與恢復(資料庫資料遷移)MongoDB資料庫
- vivo 資料庫備份恢復系統演化資料庫
- MySQL-19.資料庫備份與恢復MySql資料庫
- PG-pg_dump備份/恢復資料庫資料庫
- 備份與恢復:Polardb資料庫資料基於時間點恢復資料庫
- 【伺服器儲存資料恢復】HP-Lefthand儲存資料恢復案例伺服器資料恢復
- 【儲存資料恢復】esx vmfs的互斥導致儲存資料丟失的資料恢復案例資料恢復
- Mysql資料庫自動備份MySql資料庫
- Dedecms資料庫恢復與備份的兩種方法資料庫
- 淺談達夢資料庫的備份與恢復資料庫
- gitlab的資料備份和恢復Gitlab
- 【儲存資料恢復】某品牌EqualLogic系列儲存介紹和資料恢復方法資料恢復
- 【儲存資料恢復】IBM儲存檔案NTFS系統損壞的資料恢復案例資料恢復IBM
- 【儲存資料恢復】儲存上的raid5陣列崩潰的資料恢復案例資料恢復AI陣列
- NoSQL 資料庫案例實戰 -- MongoDB資料備份、恢復SQL資料庫MongoDB