<?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>Retiffy Developers</title>
	<atom:link href="https://dev.retiffy.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://dev.retiffy.com</link>
	<description></description>
	<lastBuildDate>Thu, 11 Apr 2013 07:11:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Distribute backups to local machines</title>
		<link>https://dev.retiffy.com/2013/04/11/distribute-backups-to-local-machines/</link>
		<comments>https://dev.retiffy.com/2013/04/11/distribute-backups-to-local-machines/#comments</comments>
		<pubDate>Thu, 11 Apr 2013 07:06:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://dev.retiffy.com/?p=126</guid>
		<description><![CDATA[If you are a team as ours you are probably working remotely, with laptops, anywhere you can, anytime you can. This mean that all of our machines are &#8220;on the cloud&#8221;, they do run, scale and backup entirely automatically. But&#8230;]]></description>
				<content:encoded><![CDATA[<p>If you are a team as ours you are probably working remotely, with laptops, anywhere you can, anytime you can. This mean that all of our machines are &#8220;on the cloud&#8221;, they do run, scale and backup entirely automatically.</p>
<p>But what if you want to add one more line of defense &#8211; copying the backups locally to your machine from time to time. In this way even if in sequence of unlikely and strange events that corrupt your remote machines, you would have a local backup of your important information. But as in our case most of the time we forget to do a copy to a local machine. That&#8217;s why I would like to make it automatic.</p>
<p>What we are currently doing is copying a backup from remote to local every time your machine starts its Internet interface. And yes, this would would not scale for GB backups. But we are still not there.</p>
<p>This is the script:</p>
<blockquote><p>#! /bin/sh</p>
<p># Copies production_backup on this machine</p>
<p># This script should be copied at /etc/network/if-up.d/. In this way everytime the network starts a backup would be made<br />
export REPOSITORY=/home/kireto/robopartans/rbp.cm<br />
export USER_WITH_ACCESS=kireto</p>
<p>&nbsp;</p>
<p>echo &#8220;Starting script:&#8221; &gt;&gt; /tmp/production_backup_copy.log<br />
set -e</p>
<p>&nbsp;</p>
<p># Don&#8217;t bother when lo is configured.<br />
if [ "$IFACE" = lo ]; then<br />
exit 0<br />
fi</p>
<p>&nbsp;</p>
<p>#~ # Only run from ifup.<br />
if [ "$MODE" != start ]; then<br />
exit 0<br />
fi</p>
<p>&nbsp;</p>
<p>FILE=&#8221;production_backup$(date +&#8217;%Y_%m_%d&#8217;).sql.gz&#8221;<br />
LOCAL_PATH=&#8221;$REPOSITORY/$FILE&#8221;<br />
REMOTE_PATH=&#8221;\&#8221;/var/jenkins/jobs/Production\\ backup/workspace/$FILE\&#8221;"</p>
<p>if [ -f $LOCAL_PATH ]; then<br />
echo &#8220;File exists locally&#8221; &gt;&gt; /tmp/production_backup_copy.log<br />
exit 0<br />
fi</p>
<p>&nbsp;</p>
<p>sudo su &#8211; $USER_WITH_ACCESS -c &#8220;cd $REPOSITORY; scp root@elvis:$REMOTE_PATH .&#8221;<br />
echo &#8220;Pulling at: $(date +&#8221;%D %T&#8221;)&#8221; &gt;&gt; /tmp/production_backup_copy.log</p>
<p>exit 0</p></blockquote>
<p>This script is then added at</p>
<blockquote><p>/etc/network/if-up.d</p></blockquote>
<p>Now we have a distributed backup system, where simultaneous fail of all the machines and processes is impossible (except if someone starts a earth big <a href="http://en.wikipedia.org/wiki/Electromagnetic_pulse">Electromagnetic impulse</a>)</p>
]]></content:encoded>
			<wfw:commentRss>https://dev.retiffy.com/2013/04/11/distribute-backups-to-local-machines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backup production mysql in Git</title>
		<link>https://dev.retiffy.com/2013/04/11/backup-production-mysql-in-git/</link>
		<comments>https://dev.retiffy.com/2013/04/11/backup-production-mysql-in-git/#comments</comments>
		<pubDate>Thu, 11 Apr 2013 06:20:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://dev.retiffy.com/?p=118</guid>
		<description><![CDATA[Truth be told this is not a good Idea. Here is our experience. Our server runs on a machine with a mysql as a database. Since we are a number of people on the team we decided to do this&#8230;]]></description>
				<content:encoded><![CDATA[<p>Truth be told this is not a good Idea. Here is our experience.</p>
<p>Our server runs on a machine with a mysql as a database. Since we are a number of people on the team we decided to do this marvelous, genius idea. We would backup our production database every day with a sql dump and commit this dump it into git. Then when each of us does his normal job and checkouts other code changes he would also checkout the database. And the best part is that Git can manage differences between files so we are not actually storing the whole file. We store only the differences and this difference most of the time is in the users table &#8211; who has logged in, when, what has he done.</p>
<p>As a result we would have the database and all of it history distributed on several machines and we would have the whole history of each and every day. Just genius.</p>
<p>Turns out this is not a good idea. It took git only 315 commits of our not that large 50 MB database to stop working. This &#8220;fast&#8221;, &#8220;supppper speed&#8221;, &#8220;one of a kind&#8221; version control system just stopped working after the 315 build <img src='https://dev.retiffy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . When we were trying to pull and this was the error occurring:</p>
<blockquote><p>remote: Counting objects: 677, done.<br />
error: pack-objects died of signal 9/461)<br />
error: git upload-pack: git-pack-objects died with error.<br />
fatal: git upload-pack: aborting due to possible repository corruption on the remote side.<br />
remote: aborting due to possible repository corruption on the remote side.<br />
fatal: protocol error: bad pack header</p></blockquote>
<p>So we took another approach</p>
<ul>
<li>Delete the whole backup branch locally and remotely</li>
</ul>
<blockquote><p>git branch -D production_backup</p></blockquote>
<blockquote><p>git push origin &#8211;delete production_backup</p>
<p><em>(locally)</em> &#8211; git gc</p>
<p><em>(remotely) &#8211; </em>git gc</p></blockquote>
<ul>
<li><span style="line-height: 1.7;">Setup a new production backup process where you have daily, weekly and monthly backup</span></li>
</ul>
<ul>
<li><strong>Daily</strong> &#8211; runs every day and only the last 8 backups are saved</li>
</ul>
<blockquote><p>mysqldump &#8211;user=root &#8211;password=ThePassword &#8211;databases production | gzip &gt; production_backup$(date +&#8221;%Y_%m_%d&#8221;).sql.gz</p></blockquote>
<ul>
<li><strong>Weekly</strong> &#8211; runs every week and only the last 5 backups are saved</li>
</ul>
<blockquote><p>mysqldump &#8211;user=root &#8211;password=ThePassword &#8211;databases production | gzip &gt; production_backup$(date +&#8221;%Y_%m_%d&#8221;).sql.gz</p></blockquote>
<ul>
<li><strong>Monthly</strong> &#8211; runs every month and only the last 13 are saved.</li>
</ul>
<blockquote><p>mysqldump &#8211;user=root &#8211;password=ThePassword &#8211;databases production | gzip &gt; production_backup$(date +&#8221;%Y_%m_%d&#8221;).sql.gz</p></blockquote>
<p>Take a look at the gzip part. Since sql dumps more often than not, contain text information you should always gzip them. And the <em>$(date +&#8221;%Y_%m_%d&#8221;)</em> just puts the current date in the file name.</p>
<p>Now we just have to figure our when an how to copy this backups to another machine <img src='https://dev.retiffy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://dev.retiffy.com/2013/04/11/backup-production-mysql-in-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delayed_job should be restarted on production build</title>
		<link>https://dev.retiffy.com/2013/03/25/delayed_job-should-be-restarted-on-production-build/</link>
		<comments>https://dev.retiffy.com/2013/03/25/delayed_job-should-be-restarted-on-production-build/#comments</comments>
		<pubDate>Mon, 25 Mar 2013 13:37:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[delayed_job]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://dev.retiffy.com/?p=113</guid>
		<description><![CDATA[Yes, it sounds obvious but it took me some time to figure that out. We were working on the campaigns downloads in Retiffy. This means generating a PDF for every certificate and then concatenating them into a single PDF and&#8230;]]></description>
				<content:encoded><![CDATA[<p>Yes, it sounds obvious but it took me some time to figure that out.</p>
<p>We were working on the campaigns downloads in Retiffy. This means generating a PDF for every certificate and then concatenating them into a single PDF and sending the link to the user. Now the problem is that this is done in a delayed_job and if you change the production databases and code without restarting delayed_job, the job preformed at a delay are still using the old code.</p>
<p>We haven`t dig deep enough to understand the internals and whether we could fix it in another way. Currently we are searching for the best solution to restart delayed_job on building production.</p>
<p>This is the initial source of the Ubuntu service that we have come up with. Hope it could help you. We will continue working on it with for restart and stop.</p>
<p>#!/bin/bash<br />
# Delayed job for Retiffy production<br />
# acts as startup service.<br />
# USAGE: start<br />
case &#8220;$1&#8243; in<br />
start)<br />
echo &#8220;Starting Delayed_job for Retiffy Production&#8221;<br />
RAILS_ENV=production<br />
export RAILS_ENV<br />
start-stop-daemon &#8211;start &#8211;pidfile /var/run/delayed_job.pid &#8211;make-pidfile &#8211;background &#8211;chuid www-data &#8211;exec /production/script/delayed_job &#8212; restart -i 2 || return 2<br />
;;</p>
<p>esac<br />
exit 0</p>
]]></content:encoded>
			<wfw:commentRss>https://dev.retiffy.com/2013/03/25/delayed_job-should-be-restarted-on-production-build/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
