From: Ian Jackson Date: Wed, 9 Sep 2009 12:42:33 +0000 (+0100) Subject: update-master-info can copy databases to rsync area X-Git-Tag: 3.4~3^2^2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=commitdiff_plain;h=c7bbf52af773c2f15cb1f2b78ee42bd0b7a60c4a update-master-info can copy databases to rsync area --- diff --git a/yarrg/update-master-info b/yarrg/update-master-info index 893b367..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'; @@ -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(); }