TimesTen学习系列之一:TT的迁移和备份

来源:互联网 发布:淘宝金币换流量 编辑:程序博客网 时间:2024/05/17 06:46
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>  ----验证数据未丢失
1 0
原创粉丝点击