X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-live.git;a=blobdiff_plain;f=yarrg%2Fupdate-master-info;h=c0bbbffe1a303928159b120e66ebef046b55f8ef;hp=ba778d4049212eafe4195527a0acbe40b5e0717e;hb=a9da0efea5c7191be3fc150465c52c03a44b4765;hpb=f02ff07b3de767a0c1d118a664b14313b8c889ac diff --git a/yarrg/update-master-info b/yarrg/update-master-info index ba778d4..c0bbbff 100755 --- a/yarrg/update-master-info +++ b/yarrg/update-master-info @@ -26,6 +26,9 @@ # ./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. @@ -52,6 +55,8 @@ use strict (qw(vars)); use DBI; use Commods; +use CommodsDatabase; +use File::Copy; $ENV{'LC_CTYPE'}= 'en_GB.UTF-8'; @@ -60,6 +65,7 @@ sub full ($) { quick($ocean); print "## updating topology of $ocean\n"; system('./yppedia-chart-parser',$ocean); die "$ocean $?" if $?; + print "\n"; } sub quick ($) { @@ -88,7 +94,8 @@ sub process_some_info ($$$) { if ($v<2) { next if $h =~ m/^nocommods/; } - next if $sfn =~ m/source-info/ && $h =~ m/^ocean/; + next if $sfn =~ m/source-info/ && $h =~ m/^ocean\b/; + next if $h =~ m/^client\b/; print $df $_, "\n" or die $!; } @@ -117,6 +124,7 @@ sub update_master_info () { my @specoceans; my $alloceans; +my $backup; sub optarg () { return $_ if length; @@ -133,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 { @@ -144,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}; @@ -165,7 +191,7 @@ if (@specoceans) { } } -if (defined $rsyncdir) { +if (defined $rsyncdir and !$backup) { print "### master-info update ...\n"; update_master_info(); }