[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[4068] branches/1.3
- Subject: SF.net SVN: ledger-smb:[4068] branches/1.3
- From: ..hidden..
- Date: Fri, 25 Nov 2011 07:49:44 +0000
Revision: 4068
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=4068&view=rev
Author: einhverfr
Date: 2011-11-25 07:49:44 +0000 (Fri, 25 Nov 2011)
Log Message:
-----------
Initial rewrite of backup logic
Modified Paths:
--------------
branches/1.3/Changelog
branches/1.3/LedgerSMB/AM.pm
branches/1.3/LedgerSMB/Database.pm
branches/1.3/bin/am.pl
Modified: branches/1.3/Changelog
===================================================================
--- branches/1.3/Changelog 2011-11-25 04:15:22 UTC (rev 4067)
+++ branches/1.3/Changelog 2011-11-25 07:49:44 UTC (rev 4068)
@@ -17,6 +17,7 @@
* Corrected Action not defined error on asset import (Chris T)
* Corrected permissions issue for editing assembly (Chris T)
+
Changelog for LedgerSMB 1.3.6
* Including xelatex templates under directory templates/xedemo (Chris T)
* Fix for company name in order entry (David B)
Modified: branches/1.3/LedgerSMB/AM.pm
===================================================================
--- branches/1.3/LedgerSMB/AM.pm 2011-11-25 04:15:22 UTC (rev 4067)
+++ branches/1.3/LedgerSMB/AM.pm 2011-11-25 07:49:44 UTC (rev 4068)
@@ -1951,93 +1951,6 @@
}
-=item AM->backup($myconfig, $form);
-
-Prepares and outputs a database backup of the current "dataset" using
-"pg_dump -Fc". The means of output is determined by $form->{media}, which can
-be either 'file' or 'email'. If email is the desired form of output, the email
-address to send the backup to and who to claim it is from is determined by
-$myconfig->{email} and $myconfig->{name}. File output sends the backup directly
-out over HTTP.
-
-=cut
-
-sub backup {
-
- my ( $self, $myconfig, $form ) = @_;
-
- my $mail;
- my $err;
-
- my @t = localtime(time);
- $t[4]++;
- $t[5] += 1900;
- $t[3] = substr( "0$t[3]", -2 );
- $t[4] = substr( "0$t[4]", -2 );
-
- my $globalDBname = $myconfig->{dbname};
- my $boundary = time;
- my $tmpfile =
-"${LedgerSMB::Sysconfig::backuppath}/$boundary.$globalDBname-$form->{dbversion}-$t[5]$t[4]$t[3].sqlc";
- $form->{OUT} = "$tmpfile";
-
- open( OUT, '>:raw', "$form->{OUT}" ) or $form->error("$form->{OUT} : $!");
-
- # get sequences, functions and triggers
-
- my $today = scalar localtime;
-
-
- ##SC: START Testing changes
- $myconfig->{name} = "test";
- $myconfig->{email} = '..hidden..';
- $myconfig->{dbport} = 5432;
- $myconfig->{dbuser} = 'seneca';
- $myconfig->{dbhost} = 'localhost';
- $myconfig->{dbname} = 'ledgersmb-taxtest';
- ##SC: END Testing changes
- if ( $form->{media} eq 'email' ) {
- print OUT
-qx(PGPASSWORD="$myconfig->{dbpasswd}" pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} -Fc -p $myconfig->{dbport} $myconfig->{dbname});
- close OUT;
- use LedgerSMB::Mailer;
- $mail = new LedgerSMB::Mailer(
- to => qq|"$myconfig->{name}" <$myconfig->{email}>|,
- from => qq|"$myconfig->{name}" <$myconfig->{email}>|,
- subject => "LedgerSMB Backup / $globalDBname-$form->{dbversion}-$t[5]$t[4]$t[3].sqlc",
- message => qq|
-This PostgreSQL backup can be restored using the pg_restore command.
-
---
-LedgerSMB|,
- );
-
- $mail->attach(
- 'file' => $tmpfile,
- 'filename' => $tmpfile,
- 'strip' => "$boundary.",
- 'mimetype' => 'application/octet-stream',
- );
-
- $err = $mail->send;
- }
-
- if ( $form->{media} eq 'file' ) {
-
- #open( IN, '<:raw', "$tmpfile" ) or $form->error("$tmpfile : $!");
- open( OUT, ">-" ) or $form->error("STDOUT : $!");
- binmode( OUT, ':raw' );
-
- print OUT qq|Content-Type: application/file;\n|
- . qq|Content-Disposition: attachment; filename="$myconfig->{dbname}-$form->{dbversion}-$t[5]$t[4]$t[3].sqlc"\n\n|;
- print OUT
-qx(PGPASSWORD="$myconfig->{dbpasswd}" pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} -Fc -p $myconfig->{dbport} $myconfig->{dbname});
- }
-
- unlink "$tmpfile";
-
-}
-
=item AM->closedto($myconfig, $form);
Populates $form->{closedto}, $form->{revtrans}, and $form->{audittrail} with
Modified: branches/1.3/LedgerSMB/Database.pm
===================================================================
--- branches/1.3/LedgerSMB/Database.pm 2011-11-25 04:15:22 UTC (rev 4067)
+++ branches/1.3/LedgerSMB/Database.pm 2011-11-25 07:49:44 UTC (rev 4068)
@@ -66,10 +66,92 @@
} else {
$self->{source_dir} = '';
}
+
bless $self, $class;
return $self;
}
+=item base_backuo()
+
+This routine connects to the database using pg_dumpall and returns a plain text,
+roles-only dump of the current database cluster. This is left uncompressed for
+readability and ease of troubleshooting. Base backups are advised to be taken
+frequently and in conjunction with single database backups. The single database
+backups will backup all data but no roles. Restoring a new database onto a new
+server post-crash with only the single-database backup thus means recreating all
+users.
+
+The file is named roles_[date].sql by default where the date is in
+yyyy-mm-dd format.
+
+=cut
+
+sub base_backup {
+ my $self = shift @_;
+
+ my $old_pguser = $ENV{PGUSER};
+ my $old_pgpass = $ENV{PGPASSWORD};
+ $ENV{PGUSER} = $self->{username};
+ $ENV{PGPASSWORD} = $self->{password};
+
+ my @t = localtime(time);
+ $t[4]++;
+ $t[5] += 1900;
+ $t[3] = substr( "0$t[3]", -2 );
+ $t[4] = substr( "0$t[4]", -2 );
+ my $date = "$5-$4-$3";
+
+ my $backupfile = $LedgerSMB::Sysconfig::backuppath .
+ "/roles_${date}.sql";
+
+ system("pgdumpall -r -f '$backupfile'") || $self->error('Backup failed');
+
+ $ENV{PGUSER} = $old_pguser;
+ $ENV{PGPASSWORD} = $old_pgpass;
+
+ return $backupfile;
+}
+
+=item db_backup()
+
+This routine connects to the database using pg_dump and creates a Pg-native
+database backup of the selected db only. There is some redundancy with the base
+backup but the overlap is minimal. You can restore your database and data with
+the db_bakup, but not the users and roles. You can restore the users and roles
+with the base_backup but not your database.
+
+The resulting file is named backup_[dbname]_[date].bak with the date in
+yyyy-mm-dd format.
+
+=cut
+
+sub db_backup {
+ my $self = shift @_;
+
+ my $old_pguser = $ENV{PGUSER};
+ my $old_pgpass = $ENV{PGPASSWORD};
+ $ENV{PGUSER} = $self->{username};
+ $ENV{PGPASSWORD} = $self->{password};
+
+ my @t = localtime(time);
+ $t[4]++;
+ $t[5] += 1900;
+ $t[3] = substr( "0$t[3]", -2 );
+ $t[4] = substr( "0$t[4]", -2 );
+ my $date = "$5-$4-$3";
+
+ my $backupfile = $LedgerSMB::Sysconfig::backuppath .
+ "/backup_$self->{company_name}_${date}.sql";
+
+ system("pgdump -d '$self->{company_name}' -F c -f '$backupfile'")
+ || $self->error('Backup failed');
+
+ $ENV{PGUSER} = $old_pguser;
+ $ENV{PGPASSWORD} = $old_pgpass;
+
+ return $backupfile;
+}
+
=item get_info()
This routine connects to the database using DBI and attempts to determine if a
Modified: branches/1.3/bin/am.pl
===================================================================
--- branches/1.3/bin/am.pl 2011-11-25 04:15:22 UTC (rev 4067)
+++ branches/1.3/bin/am.pl 2011-11-25 07:49:44 UTC (rev 4068)
@@ -1787,28 +1787,6 @@
}
-sub backup {
-
- if ( $form->{media} eq 'email' ) {
- $form->error(
- $locale->text( 'No email address for [_1]', $myconfig{name} ) )
- unless ( $myconfig{email} );
- }
-
- $SIG{INT} = 'IGNORE';
- AM->backup(
- \%myconfig, \%$form,
- ${LedgerSMB::Sysconfig::userspath},
- ${LedgerSMB::Sysconfig::gzip}
- );
-
- if ( $form->{media} eq 'email' ) {
- $form->redirect(
- $locale->text( 'Backup sent to [_1]', $myconfig{email} ) );
- }
-
-}
-
sub audit_control {
$form->{title} = $locale->text('Audit Control');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.