quarta-feira, 17 de fevereiro de 2010

Clonando Banco Informix

Normalmente as empresas possuem duas instâncias do seu banco de dados: a instância de produção, que é utilizada no dia a dia pelos funcionários e clientes, e uma instância de testes ou homologação, cujo é utilizada para testar uma nova versão do aplicativo, treinamento ou outros tipos de testes. Ou seja, uma cópia fiel dos dados e estrutura de produção.
O modo mais rápido e automatizado de criar essa nova instância é simplesmente clonando-se o banco de produção. A clonagem é um procedimento simples, mas arriscado, pois se deve criar uma estrutura de chunks e dbspaces exatamente fiel a da instância que será clonada (número de arquivos iguais). Caso falte algum arquivo no listfile - veremos abaixo - ambas as instâncias irão compartilhar o mesmo arquivo físico. Isso pode vir a ser um sério problema. Abaixo um passo a passo simples de uma clonagem de um banco Informix.

1) Fazer backup da instância a ser clonada:
Editar o onconfig na sessão TAPEDEV para apontar onde será criado o backup.
Ex.:
TAPEDEV /tmp/novo_banco # Tape device path
TAPEBLK 32 # Tape block size (Kbytes)
TAPESIZE 10000000 # Maximum amount of data to put on tape (Kbytes)
2) ontape –s
Obs.: O arquivo “novo_banco” deve ter sido criado manualmente, utilizando o TOUCH. Esse arquivo irá receber o backup da instância, feito pelo ONTAPE –S.
3) Copiar um onconfig existente e editar as referências de nome antigo para a nova instância.
Manter as seguintes referências:
TAPEDEV /tmp/novo_banco # Tape device path original
ROOTPATH /d2/infdados/banco_original/dbs_root # Manter caminho original do arquivo copiado
Editar o SERVERNUM para um número que não esteja sendo utilizado
4) Editar o services para contemplar o novo informix Server e Porta. Ex.:
novo_banco 48561/tcp # instancia de homologacao
5) Editar o sqlhosts para contemplar a nova instância:
novo_banco onsoctcp 192.168.0.1 novo_banco
6) Criar arquivo listfile (de-para):
/d2/infdados/banco_original/dbs_root 0 /d2/infdados/novo_banco/dbs_root 0
/d2/infdados/banco_original/dbs_dados 0 /d2/infdados/novo_banco/dbs_dados 0
/d2/infdados/banco_original/dbs_blobs 0 /d2/infdados/novo_banco/dbs_blobs 0
/d2/infindex/banco_original/dbs_index 0 /d2/infindex/novo_banco/dbs_index 0
/d2/infindex/banco_original/dbs_temp 0 /d2/infindex/novo_banco/dbs_temp 0
ATENÇÃO! A estrutura do novo banco deve ser criada manualmente e deve ter número de arquivos exatamente igual a do banco original, chunks e dbspaces. Cada chunck e dbspace deve ter seu correspondente no novo banco. Isso deve ser feito fielmente para evitar sérios problemas no momento da clonagem, na instância original.
7) No diretório onde foi criado o arquivo listfile, executar:
ontape -r -rename -f listfile

Obs.: No Informix 10.0, pode ocorrer erro de perda de conexão, como descrito abaixo:
IC50975: WHEN THE SERVER CANNOT BE CONNECTED DURING A PHYSICAL RESTORE, ONTAPE -R DISPLAYS: PHYSICAL RESTORE FAILED - FUNCTION WRITE , Closed as program error.

Isso é um Bug corrigido em versões 10.00 UC6 e acima


Normally the companies use to have two instances of a database: the production instance, that is used by the employees and clients everyday, and another instance of tests and homologation, which us used to test a new version of the application, training or another uses. An identical copy of the production database.
The faster and automatic way to create this instance is creating a clone of the production database. The cloning process is very simple, but is also very dangerous. You must create an identical structure of dbspaces and chunks (same number of files), because if there's some file missing at the listfile - we'll see below - both instances will share the same physical file. This can become a serious problem. Bellow there're simple steps to clone an Informix database:

1) Backup the cloning instance, editing the parameter TAPEDEV to a physical file, where the backup will be made.
E.g.:
TAPEDEV /tmp/new_db # Tape device path
TAPEBLK 32 # Tape block size (Kbytes)
TAPESIZE 10000000 # Maximum amount of data to put on tape (Kbytes)
2) ontape -s
The backup will be made at the created file (using the TOUCH command).
3) Copy the production ONCONFIG file, editing the references to the new instance. Just mantain the following references:
TAPEDEV /tmp/new_db # Original Tape device path
ROOTPATH /d2/infdados/original_db/dbs_root # Keep the original ROOT path
Edit the SERVERNUM to a not used number
4) Edit the services file adding the new informix server and its backdoor:
new_db 48561/tcp # New Instance Name
5) Edit the sqlhost files adding the new instance:
New_db onsoctcp 192.168.0.1 new_db
6) Create the listfile. This file is something like a FROM-TO file, which lists the original file path and the destination file path:
/d2/infdados/original_db/dbs_root 0 /d2/infdados/new_db/dbs_root 0
/d2/infdados/original_db/dbs_dados 0 /d2/infdados/new_db/dbs_dados 0
/d2/infdados/original_db/dbs_blobs 0 /d2/infdados/new_db/dbs_blobs 0
/d2/infindex/original_db/dbs_index 0 /d2/infindex/new_db/dbs_index 0
/d2/infindex/original_db/dbs_temp 0 /d2/infindex/new_db/dbs_temp 0
BE CAREFUL! The destination structure must be manually created, and must have the same number of files (chunks and dbspaces). Every chunk and dbspace must have its pair on the destination side. This can avoid serious problems for you at the cloning moment.
7) In the path where the listfile was created, execute:
ontape -r -rename -f listfile

Observation: On Informix 10.00 maybe occurs an error of connection lost:
C50975: WHEN THE SERVER CANNOT BE CONNECTED DURING A PHYSICAL RESTORE, ONTAPE -R DISPLAYS: PHYSICAL RESTORE FAILED - FUNCTION WRITE , Closed as program error

It's a Bug, corrected on Informix 10.00 UC6 or higher.

2 comentários:

  1. You comment on the weather in Sao Paulo reminds me of how I'm always amused by the fact that the weather in Florida is so different from the weather in New England- and it is only 22 hours drive to Florida, where I have been once. It was my only experience with subtropical weather. I saw my first outdoor without them being in a pot palm trees halfway though Georgia. They had tropical hibiscus just growing in the ground- no one had to replant every year on account of them freezing to death. I saw my first bird of paradise flowers. The rest of the trip was a drag. I spent the next three days whittling down my time between going on rides with ridiculously long lines and remarking how evil the Disney Corporation is. It was almost 100 degrees F in April. I bought a new hat to keep my skin from baking to a crisp. I used up half a bottle of SPF 45 sunscreen before I left. One of my roommates made fun of me when I looking in the Gideon Bible in hope of assuaging the pain of having them for for roommates. When I got back to New England, it was raining but my peach trees were blooming for the first time.

    ResponderExcluir
  2. When I was looking in the Gideon Bible, sorry.

    ResponderExcluir

Locations of visitors to this page
Côcos pelo Mundo