[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [116] trunk
- Subject: SF.net SVN: ledger-smb: [116] trunk
- From: ..hidden..
- Date: Mon, 18 Sep 2006 22:00:54 -0700
Revision: 116
http://svn.sourceforge.net/ledger-smb/?rev=116&view=rev
Author: einhverfr
Date: 2006-09-18 22:00:52 -0700 (Mon, 18 Sep 2006)
Log Message:
-----------
Fixed backup issues
Modified Paths:
--------------
trunk/CONTRIBUTORS
trunk/Changelog
trunk/LedgerSMB/AM.pm
trunk/ledger-smb.conf
Modified: trunk/CONTRIBUTORS
===================================================================
--- trunk/CONTRIBUTORS 2006-09-19 02:46:01 UTC (rev 115)
+++ trunk/CONTRIBUTORS 2006-09-19 05:00:52 UTC (rev 116)
@@ -25,12 +25,17 @@
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.
Modified: trunk/Changelog
===================================================================
--- trunk/Changelog 2006-09-19 02:46:01 UTC (rev 115)
+++ trunk/Changelog 2006-09-19 05:00:52 UTC (rev 116)
@@ -9,6 +9,7 @@
* 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).
Modified: trunk/LedgerSMB/AM.pm
===================================================================
--- trunk/LedgerSMB/AM.pm 2006-09-19 02:46:01 UTC (rev 115)
+++ trunk/LedgerSMB/AM.pm 2006-09-19 05:00:52 UTC (rev 116)
@@ -1392,251 +1392,24 @@
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 @@
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";
Modified: trunk/ledger-smb.conf
===================================================================
--- trunk/ledger-smb.conf 2006-09-19 02:46:01 UTC (rev 115)
+++ trunk/ledger-smb.conf 2006-09-19 05:00:52 UTC (rev 116)
@@ -34,7 +34,7 @@
$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";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.