<?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>insanesecurity &#187; Backup</title>
	<atom:link href="http://insanesecurity.info/blog/tag/backup/feed" rel="self" type="application/rss+xml" />
	<link>http://insanesecurity.info/blog</link>
	<description>security through a distorted eye</description>
	<lastBuildDate>Thu, 25 Feb 2010 22:31:12 +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>Twitter (tweets) backup</title>
		<link>http://insanesecurity.info/blog/twitter-tweets-backup</link>
		<comments>http://insanesecurity.info/blog/twitter-tweets-backup#comments</comments>
		<pubDate>Tue, 29 Sep 2009 02:12:43 +0000</pubDate>
		<dc:creator>dblackshell</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://insanesecurity.info/blog/?p=287</guid>
		<description><![CDATA[Today someone came to this blog searching for a twitter backup facility. I never did post such an application/script so I figured I&#8217;d share my way of backing up my tweets. I actually never backup my tweets (nothing of value would be lost), and never intend to, but for the sake of posting something I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>Today someone came to this blog searching for a twitter backup facility. I never did post such an application/script so I figured I&#8217;d share my way of backing up my tweets.</p>
<p>I actually never backup my tweets (nothing of value would be lost), and never intend to, but for the sake of posting something I&#8217;ve said I&#8217;d give it a go.<br />
<span id="more-287"></span></p>
<p>I&#8217;m gonna perform the backup from the command line (like a true magician) without using the twitter API, so only public tweets will be backed up.</p>
<p>Ok, first we need to know the number of tweets we are going to back up (in my case 630) and divide that number by 20 (the number of tweets per page) rounding up the result. In simple math:</p>
<pre>
630 / 20 = 31.5 ~ 32
</pre>
<p>Now we know my tweets are distributed on 32 pages.<br />
Next we retrieve the 32 different pages via wget. First variant is from a Windows terminal:</p>
<pre>
for /L %i in (1,1,32) do @wget http://twitter.com/username?page=%i
</pre>
<p>The <em>for</em> trick is something I learned from the <a href="http://blog.commandlinekungfu.com/">command line kung fu blog</a>. It will iterate from <em>1</em> to <em>32</em> and store the value in the <em>%i</em> variable. Oh, and before you hit enter don&#8217;t forget to replace the <em>username</em> with your actual twitter username.</p>
<p>The Linux version is just a transcription of the above command:</p>
<pre>
for (i=0; i<32; i++); do `wget http://twitter.com/username?page=$i`; done
</pre>
<p>Hopefully I nailed it; didn't actually test the Linux command but it should work. If not, just leave me a comment with the correction.</p>
<p>As the rest goes, it's just simple regular expression matching and replacing (format a bit the end result).</p>
<pre>
grep -o -P "&lt;span class=\"entry-content\"&gt;(.*?)&lt;/span&gt;" * &gt; brute.html
sed "s/&lt;span class=\"entry-content\"&gt;//g" brute.html | sed "s/&lt;\/span&gt;/&lt;br&gt;&lt;br&gt;/g" &gt; final.html
</pre>
<p>After executing the last two commands you should have your tweets stored in the <em>final.html</em> file.</p>
]]></content:encoded>
			<wfw:commentRss>http://insanesecurity.info/blog/twitter-tweets-backup/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>email backup with Python</title>
		<link>http://insanesecurity.info/blog/email-backup-with-python</link>
		<comments>http://insanesecurity.info/blog/email-backup-with-python#comments</comments>
		<pubDate>Thu, 02 Jul 2009 11:12:37 +0000</pubDate>
		<dc:creator>dblackshell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Backup]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://insanesecurity.info/blog/?p=99</guid>
		<description><![CDATA[In my new project (involving spam) I&#8217;ve created a script for retrieving the messages locally, which you could also use for rapidly backing up your emails. The script is aimed for retrieving the emails for multiple accounts using the POP3 protocol (via SSL). #!/usr/bin/env python import poplib, os users = { "username1":"password1", "username2":"password2" } mail_server [...]]]></description>
			<content:encoded><![CDATA[<p>In my new project (involving spam) I&#8217;ve created a script for retrieving the messages locally, which you could also use for rapidly backing up your emails.</p>
<p>The script is aimed for retrieving the emails for multiple accounts using the POP3 protocol (via SSL).<br />
<span id="more-99"></span></p>
<pre>
#!/usr/bin/env python

import poplib, os

users = {
    "username1":"password1",
    "username2":"password2"
}

mail_server = 'mail.hosting.com'

for user in users:
    m = poplib.POP3_SSL(mail_server)
    m.user(user)
    m.pass_(users[user])
    num = len(m.list()[1])
    for i in range(1, num+1):
        uid  = m.retr(i)[2]
        mail = m.retr(i)[1]
        if not os.access(user, os.F_OK):
            os.mkdir(user, 0777)
        mfile  = user+'/'+str(uid)+'.txt'
        mstore = open(mfile, 'w')
        mstore.write("\n".join(mail))
        mstore.close()
    m.quit()
</pre>
<p>Of course you should replace <code>poplib.POP3_SSL</code> with <code>poplib.POP3</code> if SSL is not supported by your mail server.</p>
<p>Hope you find it useful&#8230; going back to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://insanesecurity.info/blog/email-backup-with-python/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
