Save Your Journal

pudge on 2004-06-15T21:36:28

I just read about everybody's favorite blogger -- who shall remain nameless, because I don't wish to discuss him -- shutting down a popular blogging site he was running, without notice. One person commented thusly:

There you go boys and girls: the number one reason why you don't want to go with a hosted solution, and if you do, backup. Frequently. No matter how nice or cuddly or professional the host -- back your material up at least weekly. Never give anyone control over what happens to your writing. Never.
Sound advice, that.

Also, we are today going to be shutting down use.perl.org for some major code upgrade, which will also mean data upgrades. And something bad things happen.

So I wrote this little script, to save all my use.perl.org journals (using the SOAP interface). Share and enjoy. Only TorgoX, for now, would need to change $max.

Ideally there should be a good way to not get all the entries in the first run, but only the necessary ones. Maybe the next time I modify the SOAP interface, I'll do that. Maybe an additional parameter for get_entry, to note the last entry you don't want.

Also, if you modify a journal entry, this won't help you, as there's no last modified time or anything of the sort. Just rm your local file.

#!/usr/bin/perl
use warnings;
use strict;

$ENV{TZ} = 'GMT';

use Data::Dumper; use Date::Parse; use File::Path; use File::Spec::Functions; use SOAP::Lite;

my $host = 'use.perl.org'; my $uri = "http://$host/Slash/Journal/SOAP"; my $proxy = "http://$host/journal.pl"; my $uid = 1; my $backup = catdir($ENV{HOME}, 'Documents', 'journal', $host); my $max = 1000;

mkpath($backup);

my $journal = SOAP::Lite->uri($uri)->proxy($proxy); my $recents = $journal->get_entries($uid, $max)->result;

for my $recent (@$recents) { my $id = $recent->{id}; my $file = catfile($backup, $id); next if -e $file; my $entry = $journal->get_entry($id)->result;

open my $fh, '>', $file or die "Can't open $file: $!"; print $fh Dumper $entry; close $fh;

my $time = str2time($entry->{date}); utime $time, $time, $file; }


Just remember to change the UID

brian_d_foy on 2004-06-16T00:26:39

Pudge gets "1" because he's the first user, so everyone else has to change $uid to be their own user number. Don't waste two minutes trying to download his journal like I did.

Re:Just remember to change the UID

pudge on 2004-06-16T02:03:57

Oops. :-)

Comments?

djberg96 on 2004-06-16T01:01:34

Is there any way to save associated comments along with the entries?

Re:Comments?

pudge on 2004-06-16T03:05:16

Just screen-scraping.

praise markovBlogger

jjohn on 2004-06-16T11:16:20

Since it not only makes backups of my journal, but also serveral other peoples. :-p

That's a, uh, feature. Yeah, that's the ticket.