Páginas

terça-feira, 19 de novembro de 2013

[MySQL] - Backup da estrutura e dados separados

-- Backup da estrutura do banco de dados
mysqldump -u root --password=teste -h 127.0.0.1 -n --default-character-set=utf8 --routines --triggers --events -d -v nome_banco > c:\dump\nome_banco_estrutura.sql 2> c:\dump\nome_banco_estrutura.error

-- Backup dos dados do banco de dados
mysqldump -u root --password=teste -h 127.0.0.1 -n -R -c -t -e -v -K nome_banco > c:\dump\nome_banco_dados.sql 2> c:\dump\nome_banco_dados.error

-- Select para validar objetos importados --

SET @nome_do_schema = 'nome_banco';
Select
(select schema_name from information_schema.schemata where schema_name=@nome_do_schema) as "Nome do Banco de dados",
(SELECT Round( Sum( data_length + index_length ) / 1024 / 1024, 3 )
FROM information_schema.tables
WHERE table_schema=@nome_do_schema
GROUP BY table_schema) as "Tamanho do Banco de dados em Mega Bytes",
(select count(*) from information_schema.tables where table_schema=@nome_do_schema and table_type='base table') as "Quant. Tabelas",
(select count(*) from information_schema.statistics where table_schema=@nome_do_schema) as "Quant. Índices",
(select count(*) from information_schema.views where table_schema=@nome_do_schema) as "Quant. Views",
(select count(*) from information_schema.routines where routine_type ='FUNCTION' and routine_schema=@nome_do_schema) as "Quant. Funções",
(select COUNT(*) from information_schema.routines where routine_type ='PROCEDURE' and routine_schema=@nome_do_schema) as "Quant. Procedimentos",
(select count(*) from information_schema.triggers where trigger_schema=@nome_do_schema) as "Quant. Triggers",
(select default_collation_name from information_schema.schemata where schema_name=@nome_do_schema)"Default collation do Banco de dados",
(select default_character_set_name from information_schema.schemata where schema_name=@nome_do_schema)"Default charset do Banco de dados",
(select sum((select count(*) from information_schema.tables where table_schema=@nome_do_schema and table_type='base table')+(select count(*) from information_schema.statistics where table_schema=@nome_do_schema)+(select count(*) from information_schema.views where table_schema=@nome_do_schema)+(select count(*) from information_schema.routines where routine_type ='FUNCTION' and routine_schema=@nome_do_schema)+(select COUNT(*) from information_schema.routines where routine_type ='PROCEDURE' and routine_schema=@nome_do_schema)+(select count(*) from information_schema.triggers where trigger_schema=@nome_do_schema))) as "Total de Objetos do Banco de dados"
LIMIT 0, 1000\G

-- Validando os dados importados --
select a.TABLE_SCHEMA, a.TABLE_TYPE , a.TABLE_NAME, a.TABLE_ROWS from information_schema.tables a where a.table_schema='nome_banco';

Nenhum comentário:

Postar um comentário