<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
pre
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EstiloDeEmail17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:595.3pt 841.9pt;
        margin:70.85pt 3.0cm 70.85pt 3.0cm;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=PT-BR link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Olá comunidade, peço ajuda pra quem trabalha com Postgres em
ambiente Linux e que também escreve Shell-scripts.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<pre><font size=2 face="Courier New"><span style='font-size:10.0pt'>Preciso fazer uma rotina de backup de uma base em Postgresql 8.2.4.<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Existem centenas de tabelas na base; todas as tabelas estão no formato bhXXX_h_YYYY_MM_DD, <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>onde XXX Ã© o rótulo de um tipo de tabela e YYYY_MM_DD refere-se Ã&nbsp; data de criação da tabela.<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Eis exemplos: bheqp_h_2009_01_09, bhmul_h_2009_01_09 , bhpas_h_2009_01_09, bhpds_h_2009_01_09, etc.<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Fiz uma cópia de dados de uma tabela do servidor através do pgAdmin e obtive o seguinte comando:<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'>pg_dump.exe --host 10.98.0.83 --port 5432 --username sage <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'>--format plain --data-only --verbose --file &quot;C:\teste.sql&quot; --table &quot;\&quot;public\&quot;.\&quot;bheqp_h_2009_01_09\&quot;&quot; bhcolsl_ems_sage<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'> <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Preciso fazer um programa/script para rodar , que o usuário entre com a data inicial e final e execute o comando acima <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>de acordo com os parâmetros das datas; O arquivo gerado tem que ter o mesmo nome da tabela copiada.<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Seria algo assim como o pseudo-codigo abaixo:<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>---------------------------------------<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>./copy_tabelas 2010-01-01 2010-01-31<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>---------------------------------------<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>tipos_tabelas[] = { &#8216;mul&#8217;, &#8216;eqp&#8217;, &#8216;pas&#8217;, &#8216;pds&#8217;, &#8216;lia&#8217; };<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>For (i=0; i &lt; tipos_tabelas.lenght; i++) {<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>        data_aux = data_inicial;<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>        While (data_aux &lt;= data_final) {<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>               Nome_arquivo = data_aux || &#8216;.dados&#8217;;<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>               </span></font><span
lang=EN-US>EXCUTAR pg_dump.exe --host 10.98.0.83 --port 5432 --username sage <o:p></o:p></span></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'>                       --format plain --data-only --verbose --file &quot;&lt;&lt; Nome_arquivo &gt;&gt;&quot; --table                                                        &quot;\&quot;public\&quot;.\&quot;bheqp_h_&lt;&lt;data_aux&gt;&gt;\&quot;&quot; bhcolsl_ems_sage<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span lang=EN-US style='font-size:10.0pt'>               </span>data_aux = data_aux + 1;<o:p></o:p></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>        }<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>}<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'> <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Eu gostaria de saber como fazer isso em Shell-script. Se alguém puder dar um help. <o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>Desde já agradeço. Att.<o:p></o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'><o:p>&nbsp;</o:p></span></font></pre><pre><font
size=2 face="Courier New"><span style='font-size:10.0pt'>NEWTON TEIXEIRA DO N. JR.<o:p></o:p></span></font></pre>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

</div>


<DIV><P><HR>
<FONT color=#000080 size=1 face=arial>Aviso:<BR>"O emitente desta mensagem &eacute; respons&aacute;vel por seu conte&uacute;do e endere&ccedil;amento. Cabe ao destinat&aacute;rio cuidar quanto ao tratamento adequado. Sem a devida autoriza&ccedil;&atilde;o, a divulga&ccedil;&atilde;o, a reprodu&ccedil;&atilde;o, a distribui&ccedil;&atilde;o ou qualquer outra a&ccedil;&atilde;o em desconformidade com as normas internas da ELETRONORTE S/A s&atilde;o proibidas e pass&iacute;veis de san&ccedil;&atilde;o disciplinar, c&iacute;vel e criminal. Esta mensagem pode ser monitorada". </FONT>
</P></DIV>
</body>

</html>