<?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>/root.eu &#187; oneliners</title>
	<atom:link href="http://slashroot.eu/tag/oneliners/feed/" rel="self" type="application/rss+xml" />
	<link>http://slashroot.eu</link>
	<description>Notepad of geeky sysadmin</description>
	<lastBuildDate>Thu, 23 Jun 2011 13:04:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Loading mysql database from compressed dump</title>
		<link>http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/</link>
		<comments>http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 09:25:08 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oneliners]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=193</guid>
		<description><![CDATA[<a href="http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/" title="Loading mysql database from compressed dump"></a>Today I had to load database on mysql. There`s nothing new or exciting about it, but I encountered few problems. First one is that dump was quite big (few gigabytes) and it was compressed with gzip. (G)Unzipping it simply to &#8230;<p class="read-more"><a href="http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/" title="Loading mysql database from compressed dump"></a><p>Today I had to load database on mysql. There`s nothing new or exciting about it, but I encountered few problems. First one is that dump was quite big (few gigabytes) and it was compressed with gzip. (G)Unzipping it simply to a file would take some time, waste space on disk and it wasn`t the right way <img src='http://slashroot.eu/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  So here how I managed to decompress it and load it at the same time:</p>
<pre>gunzip -c mydbdump.sql.gz|mysql -umyuser -pmypass mydb
</pre>
<p>But then I found another problem &#8211; in my dump there was hardcoded database name. I wasn`t recovering that database, but just wanted to load it to a diffrent one. Names weren`t the same so it failed to load. I looked at the begining of that file using <strong>head </strong>command, as opening so huge file in vi(m) would probably kill the server. I found that there was two sql commands that creates database itself and use it (sql <em>use</em> command). So with a little help of <strong>sed</strong> I managed to modify my command so it looked like this:</p>
<pre>
gunzip -c mydbdump.sql.gz| sed -e '1,30s/old_dbname/mydb/'| mysql -umyuser -pmypass mydb
</pre>
<p>I limited sed`s search&amp;replace to first 30 lines, because database name was at the start of the dump file and I didn`t want to mess with the rest of the file <img src='http://slashroot.eu/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2010/04/09/loading-mysql-database-from-compressed-dump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Proste statystyki wydruków z bazą sqlite</title>
		<link>http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/</link>
		<comments>http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 11:04:45 +0000</pubDate>
		<dc:creator>root</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[oneliners]]></category>

		<guid isPermaLink="false">http://slashroot.eu/?p=90</guid>
		<description><![CDATA[<a href="http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/" title="Proste statystyki wydruków z bazą sqlite"></a>Potrzebowałem na szybko statystyk wydruków. Do tego skonstruowałem taki oto twór: perl -ne 'print "$1 $2\n" if /(\d+\/[a-zA-z]+\/20\d{2}).*for job (\d+)\./' /var/log/cups/error_log&#124;sort &#124;uniq &#124; awk '{print "insert into printouts values(\""$1"\","$2");"}'&#124; sqlite3 printouts.db Ten z pozoru niezgrabny jednolinijkowiec parsuje plik logów cupsa &#8230;<p class="read-more"><a href="http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<a href="http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/" title="Proste statystyki wydruków z bazą sqlite"></a><p>Potrzebowałem na szybko statystyk wydruków. Do tego skonstruowałem taki oto twór:</p>
<pre class='brush:perl'>
perl -ne 'print "$1 $2\n" if /(\d+\/[a-zA-z]+\/20\d{2}).*for job (\d+)\./' /var/log/cups/error_log|sort |uniq | awk '{print "insert into printouts values(\""$1"\","$2");"}'| sqlite3 printouts.db
</pre>
<p>Ten z pozoru niezgrabny jednolinijkowiec parsuje plik logów cupsa wyciągając z niego numer zadania i datę, a następnie <i>wkłada</i> to do prostej bazy sqlite`a.</p>
<p>Dzięki temu mogłem szybko wydobyć ilość wydruków na dzień. Przy niewielkiej modyfikacji można dołączyć inne pola i już grupować sobie w sqlu co tylko dusza zapragnie. Nie jest to może wyszukany przypadek &#8211; raczej ciekawostka. To samo można uzyskać również za pomocą <b>uniq -c</b>, ale perspektywy tego rozwiązania są o wiele większe.</p>
<p>Na koniec tylko polecenie tworzące trywialną strukturę bazy <b>printouts.db</b>:<br />
<code><br />
sqlite3 printouts.db 'create table printouts(date text,job int)'<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://slashroot.eu/2009/08/21/proste-statystyki-wydrukow-z-baza-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

