<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CaChi &#187; Postgresql</title>
	<atom:link href="http://cachi.temiga.org/tag/postgresql/feed/" rel="self" type="application/rss+xml" />
	<link>http://cachi.temiga.org</link>
	<description>[ TEMIGA ]</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:10:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Backup en Postgres&#8230;</title>
		<link>http://cachi.temiga.org/2007/09/10/backup-en-postgres/</link>
		<comments>http://cachi.temiga.org/2007/09/10/backup-en-postgres/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 14:52:33 +0000</pubDate>
		<dc:creator>CaChi</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Postgresl]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[Postgresql]]></category>

		<guid isPermaLink="false">http://cachi.temiga.org/2007/09/10/backup-en-postgres/</guid>
		<description><![CDATA[Llevo algunos meses trabajando con Postgres y tengo unas aplicaciones en producción esto significa que constantemente debo hacer backup de estas base de datos, pues lo que realice fue un pequeño script en bash que se encargara de hacer esto de manera automática ya que constantemente hacer el mismo procedimiento se me hacia fastidioso, aquí]]></description>
			<content:encoded><![CDATA[<p>Llevo algunos meses trabajando con <a title="Postgres" href="http://es.wikipedia.org/wiki/PostgreSQL">Postgres</a> y tengo unas aplicaciones en producción esto significa que constantemente debo hacer backup de estas base de datos, pues lo que realice fue un pequeño <a title="Bash" href="http://es.wikipedia.org/wiki/Bash" target="_blank">script en bash</a> que se encargara de hacer esto de manera automática ya que constantemente hacer el mismo procedimiento se me hacia fastidioso, aquí esta una propuesta para generar tus backup de una forma mas amigable&#8230;</p>
<p>Este script genera un backup de la Base de Datos  que cumple con los requerimientos mínimo de respaldo Creación de Base de Datos y Tablas y comando de inserción de datos.</p>
<p>Para ejecutar el script solo necesitamos indicarle unos datos básicos tales como:</p>
<ol>
<li>IP del servidor de Base de Datos.</li>
<li>Usuarios con el cual nos conectamos.</li>
<li>Nombre de la Base de Datos a respaldar.</li>
<li>Nombre del archivo, en caso de no colocar ningún nombre al archivo el script asignara uno el cual sera <strong><em>Backup-nombreBD-fecha.sql</em></strong></li>
</ol>
<p>NOTA: no es necesario colocar la extensión <strong><em>.sql</em></strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span>
<span style="color: #666666; font-style: italic;">#Funcion que muestra un msj de Bienvenida</span>
<span style="color: #000000; font-weight: bold;">function</span> bienvenida <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Script para Generar Backup de una Base de Datos en PostgreSQL&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#funcion que muestra una nueva linea</span>
<span style="color: #000000; font-weight: bold;">function</span> newLine <span style="color: #7a0874; font-weight: bold;">&#123;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
bienvenida
<span style="color: #7a0874; font-weight: bold;">echo</span> El Backup se va a generar en el Directorio <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>&quot;</span>
newLine
&nbsp;
<span style="color: #666666; font-style: italic;">#opciones del backup</span>
<span style="color: #666666; font-style: italic;">#Leyendo el host del servidor de BD</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Host. (Ej. 127.0.0.1)&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> H
&nbsp;
<span style="color: #666666; font-style: italic;">#obteniendo el Usuario</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span>
bienvenida
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Host: <span style="color: #007800;">$H</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Usuario del Servidor de Base de Datos.&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> U
&nbsp;
<span style="color: #666666; font-style: italic;">#nombre de la BD</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span>
bienvenida
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Host: <span style="color: #007800;">$H</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Usuario: <span style="color: #007800;">$U</span>&quot;</span>
newLine
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Ingrese el nombre de la Base de Datos.&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> BD
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BD</span>&quot;</span> = <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #c20cb9; font-weight: bold;">clear</span>
   bienvenida
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Host: <span style="color: #007800;">$H</span>&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Usuario: <span style="color: #007800;">$U</span>&quot;</span>
   newLine
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--&amp;gt;Debe Ingresar el nombre de la Base de Datos.&quot;</span>
   <span style="color: #c20cb9; font-weight: bold;">read</span> BD
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#nombre del archivo</span>
newLine
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Nombre de Archivo (No es necesario el &quot;</span>.sql<span style="color: #ff0000;">&quot;)&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> F
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$F</span>&quot;</span> = <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #007800;">F</span>=backup-<span style="color: #007800;">$BD</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No coloco ningun nombre al archivo. el Script asignara un nombre por defecto <span style="color: #007800;">$F</span>&quot;</span>
   newLine
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Presiones Enter para continuar...&quot;</span>
   <span style="color: #c20cb9; font-weight: bold;">read</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> pg_dump <span style="color: #660033;">-i</span> <span style="color: #660033;">-h</span> <span style="color: #007800;">$H</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">-U</span> <span style="color: #007800;">$U</span> <span style="color: #660033;">-F</span> p <span style="color: #660033;">-C</span> <span style="color: #660033;">-D</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/<span style="color: #007800;">$F</span>.sql&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BD</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> generando backup...
&nbsp;
pg_dump <span style="color: #660033;">-i</span> <span style="color: #660033;">-h</span> <span style="color: #007800;">$H</span> <span style="color: #660033;">-p</span> <span style="color: #000000;">5432</span> <span style="color: #660033;">-U</span> <span style="color: #007800;">$U</span> <span style="color: #660033;">-F</span> p <span style="color: #660033;">-C</span> <span style="color: #660033;">-D</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/<span style="color: #007800;">$F</span>-<span style="color: #007800;">$(date +%Y-%m-%d)</span>.sql&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$BD</span>&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#mostrando el archivo en la consola...</span>
<span style="color: #c20cb9; font-weight: bold;">less</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$F</span>-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>Y-<span style="color: #000000; font-weight: bold;">%</span>m-<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.sql</pre></div></div>

<p>Como siempre lo digo es solo una propuesta a muchas que deben existir en la red y espero que les sea de su gran utilidad&#8230;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcachi.temiga.org%2F2007%2F09%2F10%2Fbackup-en-postgres%2F&amp;linkname=Backup%20en%20Postgres%26%238230%3B"><img src="http://cachi.temiga.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://cachi.temiga.org/2007/09/10/backup-en-postgres/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
