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

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>  ----驗證數據未丟失
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章