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 |