<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>/dev/urandom</title>
    <description>old school hacker, zombie and daemon slayer</description>
    <link>http://durandom.de/</link>
    <atom:link href="http://durandom.de/feed.xml" rel="self" type="application/rss+xml" />
    
      <item>
        <title>pg_dump and restore a db in a container</title>
        <description>&lt;p&gt;I’m running containerized ManageIQ appliances for development.
To dump your postgres db running inside such a container you simply exec &lt;code class=&quot;highlighter-rouge&quot;&gt;pg_dump&lt;/code&gt;.
In my case not directly, because &lt;code class=&quot;highlighter-rouge&quot;&gt;pg_dump&lt;/code&gt; is a some obscure place inside the container.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker &lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;miq_latest bash -lc &lt;span class=&quot;s1&quot;&gt;'pg_dump --format custom vmdb_production'&lt;/span&gt; &amp;gt; /tmp/pg_dump.pgdata
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Start a vanilla postgres container to host your development db:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker run --name miq_pg -e &lt;span class=&quot;nv&quot;&gt;POSTGRES_USER&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;root -e &lt;span class=&quot;nv&quot;&gt;POSTGRES_DB&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;vmdb_development -d -p 5432:5432 postgres:9.5
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Now you can restore the dump&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;docker &lt;span class=&quot;nb&quot;&gt;exec&lt;/span&gt; -i miq_pg pg_restore --dbname&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;vmdb_development --verbose --clean &amp;lt; /tmp/pg_dump.pgdata
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;beware-mr-t&quot;&gt;Beware Mr. T&lt;/h3&gt;

&lt;p&gt;You might be used to run &lt;code class=&quot;highlighter-rouge&quot;&gt;docker exec -ti&lt;/code&gt; - but don’t do this to dump a db. The &lt;code class=&quot;highlighter-rouge&quot;&gt;-t, --tty&lt;/code&gt; flag 
will also append a carriage return character.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ head /tmp/pg_dump.pgdata_dos | head -1 | cat -A
PGDMP^A...@9.5.2^@M-r^M&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;

❯ head /tmp/pg_dump.pgdata | head -1 | cat -A
PGDMP^A...@9.5.2^@M-r&lt;span class=&quot;err&quot;&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Better yet, &lt;code class=&quot;highlighter-rouge&quot;&gt;pg_restore&lt;/code&gt; will just segfault on the wrong format&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ docker &lt;span class=&quot;nb&quot;&gt;exec&lt;/span&gt; -i miq_pg pg_restore --dbname&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;vmdb_development --verbose --clean &amp;lt; /tmp/pg_dump.pgdata_dos

❯ &lt;span class=&quot;nb&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$?&lt;/span&gt;
139

❯ docker run --rm -ti --link&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;miq_pg -v /tmp:/tmp postgres:9.5 bash
&lt;span class=&quot;gp&quot;&gt;root@9ce662730c82:/# &lt;/span&gt;pg_restore --dbname&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;vmdb_development --verbose --clean /tmp/pg_dump.pgdata_dos
Segmentation fault
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</description>
        <pubDate>Tue, 20 Dec 2016 11:00:00 +0000</pubDate>
        <link>http://durandom.de/docker/postgres/2016/12/20/pg_dump/</link>
        <guid isPermaLink="true">http://durandom.de/docker/postgres/2016/12/20/pg_dump/</guid>
      </item>
    
      <item>
        <title>init</title>
        <description>&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cat /dev/urandom | hexdump
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</description>
        <pubDate>Wed, 14 Dec 2016 16:08:04 +0000</pubDate>
        <link>http://durandom.de/site/2016/12/14/init/</link>
        <guid isPermaLink="true">http://durandom.de/site/2016/12/14/init/</guid>
      </item>
    
  </channel>
</rss>
