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_PRODUCTSCache group successfully saved.此时该表被导出到了/backup/a。注意如果要导出Cachegroup中的表,必须指定为CG导出,否则会报错:[root@test ~]# ttMigrate -c TT_1122 /backup/a TEST_USER.TBL_PRODUCTSttMigrate: 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_PRODUCTSSaving cache group TEST_USER.GC_TBL_PRODUCTS Saving cached table TEST_USER.TBL_PRODUCTSCache group successfully saved.导出文件可以使用ttMigrate -l/-L/-d/-D查看内容。ttMigrate也可以用于执行恢复,,具体格式为:ttMigrate -r DSN filename例如将刚才导出的文件进行恢复:[root@test ~]# ttMigrate -r TT_1122 /backup/aRestoring cache group TEST_USER.GC_TBL_PRODUCTS Restoring cached table TEST_USER.TBL_PRODUCTSttMigrate: 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/aEnter 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数据库中loadCommand> 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_1122Backup started …Backup complete全备执行完了,此时在/backup生产了备份文件。下面执行恢复.systax:ttRestore -fname ttbak -dir /backup TT_1122[root@test ~]# ttRestore -fname fileprefix -dir path TT_1122Restore 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_1122Restore 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 -stopTimesTen Daemon stopped. [root@test TimesTen]# ttstatusttStatus: Could not connect to the TimesTen daemon.If the TimesTen daemon is not running, please start itby running "ttDaemonAdmin -start".[root@test TimesTen]# ttRestore -fname ttbak -dir /backup TT_1122ttRestore: TimesTen daemon is not running[root@test TimesTen]# ttDaemonAdmin -start —-重启DaemonTimesTen Daemon startup OK.[root@test TimesTen]# ttRestore -fname ttbak -dir /backup TT_1122Restore started …Restore complete[root@test TimesTen]# —完成restoreCommand> select count(*) from x;< 22000 >1 row found.Command> —-验证数据未丢失

人生伟业的建立,不在能知,乃在能行。

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

相关文章:

你感兴趣的文章:

标签云: