TimesTen學習系列之一:TT的遷移和備份,timesten系列之一

來源:互聯網
上載者:User

TimesTen學習系列之一:TT的遷移和備份,timesten系列之一
TimesTen可以使用ttMigrate進行遷移,類似於Oracle的exp/imp。
具體用法文檔上寫得非常詳細了,或者可以執行ttMigrate --help查看。
我這裡只對幾個常見的使用情境進行記錄。


1)匯出單表:
可以使用下面格式:
ttMigrate -c|-a DSN|ConnectStr 檔案名稱 對象名
-c表示已建立的格式匯出
-a表示追加匯出
匯出的對象可以是cachegroup/table/sequence/view等等
例如:匯出某一個表
[root@test ~]# ttMigrate -c TT_1122 /backup/a TEST_USER.TBL_PRODUCTS
  Saving cached table TEST_USER.TBL_PRODUCTS
Cache group successfully saved.

此時該表被匯出到了/backup/a。
注意如果要匯出Cachegroup中的表,必須指定為CG匯出,否則會報錯:
[root@test ~]# ttMigrate -c TT_1122 /backup/a TEST_USER.TBL_PRODUCTS
ttMigrate: Error received while processing table TEST_USER.TBL_PRODUCTS -- table can only be saved by saving cache group TEST_USER.GC_TBL_PRODUCTS.
[root@test ~]# ttMigrate -c TT_1122 /backup/a TEST_USER.GC_TBL_PRODUCTS
Saving cache group TEST_USER.GC_TBL_PRODUCTS
  Saving cached table TEST_USER.TBL_PRODUCTS
Cache group successfully saved.
匯出檔案可以使用ttMigrate -l/-L/-d/-D查看內容。
ttMigrate也可以用於執行恢複,具體格式為:
ttMigrate -r DSN filename
例如將剛才匯出的檔案進行恢複:
[root@test ~]# ttMigrate -r TT_1122 /backup/a


Restoring cache group TEST_USER.GC_TBL_PRODUCTS
  Restoring cached table TEST_USER.TBL_PRODUCTS
ttMigrate: Error received while restoring cache group TEST_USER.GC_TBL_PRODUCTS -- 37000: [TimesTen][TimesTen 11.2.2.8.0 ODBC Driver][TimesTen]TT8224: Cache group GC_TBL_PRODUCTS already exists -- file "plittddl.c", lineno 737, procedure "plittCreate" (TimesTen error code = 8224).
*** Cache group TEST_USER.GC_TBL_PRODUCTS was not restored.
There were errors restoring the following objects:
  cache group TEST_USER.GC_TBL_PRODUCTS
此時提示TT中已經存在該CG,於是我們將CG刪除之後再恢複:
Command> select count(*) from tbl_products;   ---刪除前查看資料量
< 10150 >
1 row found.
Command> 
Command> drop cache group TEST_USER.GC_TBL_PRODUCTS;
[root@test ~]# ttMigrate -r "dsn=TT_1122;uid=TEST_USER;oraclepwd=TEST_USER" /backup/a
Enter password for 'TEST_USER': 


Restoring cache group TEST_USER.GC_TBL_PRODUCTS
  Restoring cached table TEST_USER.TBL_PRODUCTS
  1/1 cached table restored.
Cache group successfully restored.
已經匯入成功了。
但此時我們查看錶,發現還沒有從資料庫中load資料。


Command> select count(*) from tbl_products;
< 0 >
1 row found.


原來,ttMigrate對於cg只會備份定義,資料還是從Oracle資料庫中load
Command> alter  cache group  GC_TBL_PRODUCTS set AUTOREFRESH interval 5 seconds;


Command> call ttcachestart
       > ;
Command> select count(*) from tbl_products;
< 0 >
1 row found.


1 row found.
Command> alter  cache group  GC_TBL_PRODUCTS set AUTOREFRESH interval 5 seconds;
Command> select count(*) from tbl_products;
< 0 >
1 row found.
Command> alter  cache group  GC_TBL_PRODUCTS set AUTOREFRESH state paused;
Command> load cache group GC_TBL_PRODUCTS commit every 500 rows ;  
10154 cache instances affected.
Command> load cache group GC_TBL_PRODUCTS commit every 500 rows;
以上是匯出單個對象的例子。


2)匯出整個資料庫
如果不指定要匯出的對象,那麼ttMigrate會將整個資料庫匯出,例如
[root@test ~]# ttMigrate -c TT_1122 /backup/a


物理備份與恢複:
Timesten對物理備份恢複使用了2個工具ttBackup和ttRestore,文檔上對這2個工具的使用方法說得非常詳細,
下面簡單記錄下對資料庫做全備和恢複的過程。
Syntax:
ttBackup -dir path -type bktype -fname fileprefix DSN
例如:
[root@test ~]# ttBackup -dir /backup -type fileFull -fname ttbak TT_1122
Backup started ...
Backup complete


全備執行完了,此時在/backup生產了備份檔案。
下面執行恢複.
systax:
ttRestore -fname ttbak -dir /backup TT_1122
[root@test ~]# ttRestore -fname fileprefix -dir path TT_1122
Restore started ...
Restore failed:
Error 12133: TT12133: Data store file already exists -- file "restore.c", lineno 1006, procedure "doRestore"  ---報錯
[root@test TimesTen]# rm -rf /var/TimesTen/tt1122/TT_1122.ds*   ---刪除掉ds檔案
[root@test TimesTen]# ttRestore -fname ttbak -dir /backup TT_1122   
Restore started ...
Restore failed:
Error 12134: TT12134: Log file(s) already exist -- file "restore.c", lineno 1040, procedure "doRestore"  ---報錯logfile存在
You have new mail in /var/spool/mail/root


[root@test TimesTen]# 
[root@test TimesTen]# rm -rf /var/TimesTen/tt1122/TT_1122.log13*   ---刪除掉log檔案
[root@test TimesTen]# ttRestore -fname ttbak -dir /backup TT_1122
Restore started ...
Restore failed:
Error 12116: TT12116: Cannot create database for restore -- file "restore.c", lineno 1808, procedure "dsCreate"
Error 839: TT0839: Cannot access data store because it is in use. A data store may be considered to be in use due to its RAM Policy setting, even though there are no active connections to it. -- file "db.c", lineno 20680, procedure "sbDbDestroy"
Error 830: TT0830: Cannot create data store file. OS-detected error: Could not destroy previous data store -- file "db.c", lineno 7788, procedure "sbDbCreate"
---此時有串連存在未釋放,不允許建立DS
[root@test TimesTen]# 
[root@test TimesTen]# ttDaemonAdmin -stop 
TimesTen Daemon stopped.  
[root@test TimesTen]# ttstatus 
ttStatus: Could not connect to the TimesTen daemon.
If the TimesTen daemon is not running, please start it
by running "ttDaemonAdmin -start".
[root@test TimesTen]# ttRestore -fname ttbak -dir /backup TT_1122
ttRestore: TimesTen daemon is not running
[root@test TimesTen]# ttDaemonAdmin -start           ----重啟Daemon
TimesTen Daemon startup OK.
[root@test TimesTen]# ttRestore -fname ttbak -dir /backup TT_1122
Restore started ...
Restore complete
[root@test TimesTen]#  ---完成restore
Command> select count(*) from x;
< 22000 >
1 row found.
Command>  ----驗證資料未丟失

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.