Save Your Journal

| | Comments (0)
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;
}

use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on June 15, 2004 2:36 PM.

Sunday Thoughts was the previous entry in this site.

Sunday Thoughts is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.