X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Fupdate-master-info;h=adad34c81f42fbd29dbc2d0f9b24a7a392bda272;hp=b16e7b4704b4e486b4426ad423a81656bdd4d873;hb=4ee718187692e362a0e274020a0ad61701f1b2de;hpb=f02d4b019d25b89202557545917f76d721bbb1cc diff --git a/yarrg/update-master-info b/yarrg/update-master-info index b16e7b4..adad34c 100755 --- a/yarrg/update-master-info +++ b/yarrg/update-master-info @@ -26,23 +26,26 @@ # ./update-master-info -a # and check that nothing unexpected changes. # +# To just make backups of the databases into the rsync directory: +# ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -a +# ./update-master-info -b -d ~ftp/users/ijackson/yarrg/ -O ... -# This is part of ypp-sc-tools, a set of third-party tools for assisting -# players of Yohoho Puzzle Pirates. +# This is part of the YARRG website. YARRG is a tool and website +# for assisting players of Yohoho Puzzle Pirates. # # Copyright (C) 2009 Ian Jackson # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# GNU Affero General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # Yohoho and Puzzle Pirates are probably trademarks of Three Rings and @@ -52,6 +55,8 @@ use strict (qw(vars)); use DBI; use Commods; +use CommodsDatabase; +use File::Copy; $ENV{'LC_CTYPE'}= 'en_GB.UTF-8'; @@ -90,7 +95,7 @@ sub process_some_info ($$$) { next if $h =~ m/^nocommods/; } next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/; - next if $h =~ m/^client|^vessels|^shot\b/; + next if $h =~ m/^client|^vessels|^shot\b|^commodclasses/; print $df $_, "\n" or die $!; } @@ -119,6 +124,7 @@ sub update_master_info () { my @specoceans; my $alloceans; +my $backup; sub optarg () { return $_ if length; @@ -135,7 +141,10 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { $rsyncdir= optarg(); } elsif (s/^-O//) { push @specoceans, optarg(); - } elsif (s/^-a//) { + } elsif (s/^-b/-/) { + die if $backup; + $backup=1; + } elsif (s/^-a/-/) { die if $alloceans; $alloceans=1; } else { @@ -146,10 +155,25 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { die if @ARGV; die if @specoceans && $alloceans; +die if $backup && !$alloceans && !@specoceans; parse_info_serverside(); -if (@specoceans) { +if ($backup) { + my @oceans= $alloceans ? (sort keys %oceans) : @specoceans; + foreach my $ocean (@oceans) { + print "## database backup for $ocean\n"; + db_setocean($ocean); + db_writer(); + db_connect(); + $dbh->selectall_arrayref("SELECT * FROM commods WHERE commodid=1"); + my $src= db_filename(); + my $dst= $src; $dst =~ s,.*/,,; $dst= "$rsyncdir/$dst"; + copy($src,"$dst.tmp") or die "$src -> $dst.tmp $!"; + rename("$dst.tmp",$dst) or die "$dst.tmp -> $dst $!"; + $dbh->rollback(); + } +} elsif (@specoceans) { print "### full update of specified oceans ...\n"; foreach my $ocean (@specoceans) { die "$ocean ?" unless defined $oceans{$ocean}; @@ -167,7 +191,7 @@ if (@specoceans) { } } -if (defined $rsyncdir) { +if (defined $rsyncdir and !$backup) { print "### master-info update ...\n"; update_master_info(); }