]> git.sesse.net Git - wloh/commitdiff
Back up all tables, not just the ones we need themselves.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 19 Mar 2012 13:45:13 +0000 (14:45 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 19 Mar 2012 13:45:13 +0000 (14:45 +0100)
sync.pl

diff --git a/sync.pl b/sync.pl
index 5996e203228ed0a33e8ba05a19d33ef65e954315..965b6e83a606cf8d3daeeca54de7ed9816aeb7d5 100755 (executable)
--- a/sync.pl
+++ b/sync.pl
@@ -7,6 +7,19 @@ use Encode;
 use Time::HiRes;
 require './config.pm';
 
+sub copy_escape {
+       my $x = shift;
+       if (!defined($x)) {
+               return '\N';
+       }
+       $x = Encode::decode('iso8859-1', $x);
+       $x =~ s/\\/\\\\/g;
+       $x =~ s/\r/\\r/g;
+       $x =~ s/\n/\\n/g;
+       $x =~ s/\t/\\t/g;
+       return $x;
+}
+
 sub sync_table {
        my ($mdbh, $sdbh, $table) = @_;
        my $start = [ Time::HiRes::gettimeofday ];
@@ -19,7 +32,7 @@ sub sync_table {
        $sdbh->do("COPY $table FROM STDIN");
        
        for my $row (@$data) {
-               $sdbh->pg_putcopydata(join("\t", map { Encode::decode('iso8859-1', $_ // '\N') } (@$row)) . "\n");
+               $sdbh->pg_putcopydata(join("\t", map { copy_escape($_) } (@$row)) . "\n");
        }
        $sdbh->pg_putcopyend();
        $elapsed = Time::HiRes::tv_interval($start);
@@ -36,10 +49,21 @@ my $sdbh = DBI->connect($config::local_connstr, $config::local_username, $config
 $sdbh->{AutoCommit} = 0;
 $sdbh->{RaiseError} = 1;
 
+# For our own enjoyment.
 sync_table($mdbh, $sdbh, "Fotballbrukere");
 sync_table($mdbh, $sdbh, "Fotballdeltagere");
 sync_table($mdbh, $sdbh, "Fotballresultater");
 sync_table($mdbh, $sdbh, "Fotballserier");
 
+# Just for backup.
+sync_table($mdbh, $sdbh, 'Fotballjuks');
+sync_table($mdbh, $sdbh, 'FotballKaffeklubb');
+sync_table($mdbh, $sdbh, 'Fotballkommentarer');
+sync_table($mdbh, $sdbh, 'Fotballkommentartema');
+sync_table($mdbh, $sdbh, 'FotballLogin');
+sync_table($mdbh, $sdbh, 'Fotballspraak');
+sync_table($mdbh, $sdbh, 'Fotballtoppti');
+sync_table($mdbh, $sdbh, 'Fotballvariabler');
+
 $mdbh->rollback();
 $sdbh->commit();