diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-09-19 05:00:52 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2006-09-19 05:00:52 +0000 |
commit | 22ef8cb0ad0ac9758c3d9dde8b798350a4ba7583 (patch) | |
tree | 44d2b2dcfe787b7041aca3393fc6c2a378c3f751 | |
parent | 8449cce4451570fc8a0cd2df3565e0d0de0b7fae (diff) |
Fixed backup issues
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@116 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r-- | CONTRIBUTORS | 7 | ||||
-rw-r--r-- | Changelog | 1 | ||||
-rwxr-xr-x | LedgerSMB/AM.pm | 255 | ||||
-rw-r--r-- | ledger-smb.conf | 2 |
4 files changed, 20 insertions, 245 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ca9478d0..59796053 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -25,12 +25,17 @@ the documentation. Jason Rodriguez <jasonjayr+ledgersmb @ gmail.com> provided the logic to force the password change in the admin.pl +Christopher Browne <cbrowne @ acm.org> provided some corrections to the +documentation. + +Seneca Cunningham <tentra @ gmail.com> provided some bug fixes to the upgrade +from 1.0.0 to 1.1.0 + Original Authors of SQL-Ledger: =================================== Dieter Simader <dsimader @ sql-ledger.com> Original author of SQL-Ledger, on which LedgerSMB is based. He also owns DWS Systems, Inc. -Christopher Browne <cbrowne @ acm.org> Tony Fraser <tony @ sybaspace.com> Both of the above are mentioned as contributors to a single file in SQL-Ledger. @@ -9,6 +9,7 @@ Database * FLOAT datatypes removed from database * Protection against duplicate transaction id's. * Added foreign key constraint to acc_trans.chart_id +* Database backups now use pg_dump Security * One is required to change the admin password when it is blank (on first login etc). diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm index 93faac07..917fd338 100755 --- a/LedgerSMB/AM.pm +++ b/LedgerSMB/AM.pm @@ -1392,251 +1392,24 @@ sub backup { open(OUT, "$form->{OUT}") or $form->error("$form->{OUT} : $!"); # get sequences, functions and triggers - my @tables = (); - my @sequences = (); - my @functions = (); - my @triggers = (); - my @schema = (); - - # get dbversion from -tables.sql - my $file = "$myconfig->{dbdriver}-tables.sql"; - - open(FH, "sql/$file") or $form->error("sql/$file : $!"); - - my @a = <FH>; - close(FH); - - @dbversion = grep /defaults \(version\)/, @a; - - $dbversion = "@dbversion"; - $dbversion =~ /(\d+\.\d+\.\d+)/; - $dbversion = User::calc_version($1); - - opendir SQLDIR, "sql/." or $form->error($!); - @a = grep /$myconfig->{dbdriver}-upgrade-.*?\.sql$/, readdir SQLDIR; - closedir SQLDIR; - - my $mindb; - my $maxdb; - - foreach my $line (@a) { - - $upgradescript = $line; - $line =~ s/(^$myconfig->{dbdriver}-upgrade-|\.sql$)//g; - - ($mindb, $maxdb) = split /-/, $line; - $mindb = User::calc_version($mindb); - - next if $mindb < $dbversion; - - $maxdb = User::calc_version($maxdb); - - $upgradescripts{$maxdb} = $upgradescript; - } - - - $upgradescripts{$dbversion} = "$myconfig->{dbdriver}-tables.sql"; - $upgradescripts{functions} = "$myconfig->{dbdriver}-functions.sql"; - - if (-f "sql/$myconfig->{dbdriver}-custom_tables.sql") { - $upgradescripts{customtables} = "$myconfig->{dbdriver}-custom_tables.sql"; - } - - if (-f "sql/$myconfig->{dbdriver}-custom_functions.sql") { - $upgradescripts{customfunctions} = "$myconfig->{dbdriver}-custom_functions.sql"; - } - - foreach my $key (sort keys %upgradescripts) { - - $file = $upgradescripts{$key}; - - open(FH, "sql/$file") or $form->error("sql/$file : $!"); - - push @schema, qq|-- $file\n|; - - while (<FH>) { - - if (/create table (\w+)/i) { - push @tables, $1; - } - - if (/create sequence (\w+)/i) { - push @sequences, $1; - next; - } - - if (/end function/i) { - push @functions, $_; - $function = 0; - $temp = 0; - next; - } - - if (/create function /i) { - $function = 1; - } - - if ($function) { - push @functions, $_; - next; - } - - if (/end trigger/i) { - push @triggers, $_; - $trigger = 0; - next; - } - - if (/create trigger/i) { - $trigger = 1; - } - - if ($trigger) { - push @triggers, $_; - next; - } - - push @schema, $_ if $_ !~ /^(insert|--)/i; - - } - - close(FH); - - } - - - # connect to database - my $dbh = $form->dbconnect($myconfig); my $today = scalar localtime; $myconfig->{dbhost} = 'localhost' unless $myconfig->{dbhost}; - print OUT qq|-- LedgerSMB Backup --- Dataset: $myconfig->{dbname} --- Version: $form->{dbversion} --- Host: $myconfig->{dbhost} --- Login: $form->{login} --- User: $myconfig->{name} --- Date: $today --- -|; - - - @tables = grep !/^temp/, @tables; + $ENV{PGPASSWD} = $myconfig->{dbpasswd}; # drop tables and sequences - for (@tables) { print OUT qq|DROP TABLE $_;\n| } - - print OUT "--\n"; - - # triggers and index files are dropped with the tables - - # drop functions - foreach $item (@functions) { - if ($item =~ /create function (.*\))/i) { - print OUT qq|DROP FUNCTION $1;\n|; - } - } - - # create sequences - foreach $item (@sequences) { - - if ($myconfig->{dbdriver} eq 'DB2') { - $query = qq|SELECT NEXTVAL FOR $item FROM sysibm.sysdummy1|; - } else { - $query = qq|SELECT last_value FROM $item|; - } - - my ($id) = $dbh->selectrow_array($query); - - if ($myconfig->{dbdriver} eq 'DB2') { - print OUT qq|DROP SEQUENCE $item RESTRICT - CREATE SEQUENCE $item AS INTEGER START WITH $id INCREMENT BY 1 MAXVALUE 2147483647 MINVALUE 1 CACHE 5;\n|; - } else { - if ($myconfig->{dbdriver} eq 'Pg') { - print OUT qq|CREATE SEQUENCE $item; - SELECT SETVAL('$item', $id, FALSE);\n|; - } else { - print OUT qq|DROP SEQUENCE $item - CREATE SEQUENCE $item START $id;\n|; - } - } - } - - print OUT "--\n"; - - # add schema - print OUT @schema; - print OUT "\n"; - - print OUT qq|-- set options| . - qq|$myconfig->{dboptions};| . - qq|--|; - - my $query; - my $sth; - my @arr; - my $fields; - - foreach $table (@tables) { - - $query = qq|SELECT * FROM $table|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - $query = qq|INSERT INTO $table (|; - $query .= join ',', (map { $sth->{NAME}->[$_] } (0 .. $sth->{NUM_OF_FIELDS} - 1)); - $query .= qq|) VALUES|; - - while (@arr = $sth->fetchrow_array) { - - $fields = "("; - - $fields .= join ',', map { $dbh->quote($_) } @arr; - $fields .= ")"; - - print OUT qq|$query $fields;\n|; - } - - $sth->finish; - } - - print OUT "--\n"; - - # functions - for (@functions) { print OUT $_ } - - # triggers - for (@triggers) { print OUT $_ } - - # add the index files - open(FH, "sql/$myconfig->{dbdriver}-indices.sql"); - @a = <FH>; - close(FH); - print OUT @a; - - close(OUT); - - $dbh->disconnect; # compress backup if gzip defined my $suffix = ""; - if ($gzip) { - my @args = split / /, $gzip; - my @s = @args; - - push @args, "$tmpfile"; - system(@args) == 0 or $form->error("$args[0] : $?"); - - shift @s; - my %s = @s; - $suffix = ${-S} || ".gz"; - $tmpfile .= $suffix; - } - if ($form->{media} eq 'email') { - + if ($gzip){ + print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname} | $gzip`; + } else { + print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname}`; + } + close OUT; use LedgerSMB::Mailer; $mail = new Mailer; @@ -1659,17 +1432,13 @@ sub backup { open(OUT, ">-") or $form->error("STDOUT : $!"); print OUT qq|Content-Type: application/file;\n| . - qq|Content-Disposition: attachment; filename="$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql$suffix"\n|; - binmode(IN); - binmode(OUT); - - while (<IN>) { - print OUT $_; + qq|Content-Disposition: attachment; filename="$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sql$suffix"\n\n|; + if ($gzip){ + print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname} | $gzip`; + } else { + print OUT `pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} $myconfig->{dbname}`; } - close(IN); - close(OUT); - } unlink "$tmpfile"; diff --git a/ledger-smb.conf b/ledger-smb.conf index 86f909d9..0589278c 100644 --- a/ledger-smb.conf +++ b/ledger-smb.conf @@ -34,7 +34,7 @@ $latex = 1; $gzip = "gzip -S .gz"; # if the server can't find gzip, latex, dvips or pdflatex, add the path -$ENV{PATH} .= ":/usr/local/bin"; +$ENV{PATH} .= ":/usr/local/bin:/usr/local/pgsql/bin"; # on mac os X using Fink's Perl libs, add the path #$ENV{PERL5LIB} .= ":/sw/lib/perl5"; |