[vhffs-dev] [507] Added a robot to dump postgresql database, no password auth is supported at the moment, improved mysql dump robot |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
- To: vhffs-dev@xxxxxxxxx
- Subject: [vhffs-dev] [507] Added a robot to dump postgresql database, no password auth is supported at the moment, improved mysql dump robot
- From: subversion@xxxxxxxxx
- Date: Thu, 08 Mar 2007 18:21:11 +0100
Revision: 507
Author: gradator
Date: 2007-03-08 17:21:10 +0000 (Thu, 08 Mar 2007)
Log Message:
-----------
Added a robot to dump postgresql database, no password auth is supported at the moment, improved mysql dump robot
Modified Paths:
--------------
branches/vhffs_4.1/vhffs-api/src/Vhffs/Conf.pm
branches/vhffs_4.1/vhffs-backend/conf/vhffs.conf
branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl
Added Paths:
-----------
branches/vhffs_4.1/vhffs-robots/src/dump_pgsql.pl
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Conf.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Conf.pm 2007-03-08 11:44:10 UTC (rev 506)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Conf.pm 2007-03-08 17:21:10 UTC (rev 507)
@@ -414,7 +414,12 @@
return $Config{"services"}{"mysql"}{"username"};
}
+sub get_mysql_mysqldump_path
+{
+ return $Config{"services"}{"mysql"}{"mysqldump_path"};
+}
+
sub get_pgsql_admin_pass
{
return $Config{"services"}{"postgresql"}{"password"};
@@ -430,7 +435,12 @@
return $Config{"services"}{"postgresql"}{"username"};
}
+sub get_pgsql_pgdump_path
+{
+ return $Config{"services"}{"postgresql"}{"pgdump_path"};
+}
+
sub get_svn_repodir
{
if( defined $Config{"services"}{"subversion"}{"repo_dir"} )
Modified: branches/vhffs_4.1/vhffs-backend/conf/vhffs.conf
===================================================================
--- branches/vhffs_4.1/vhffs-backend/conf/vhffs.conf 2007-03-08 11:44:10 UTC (rev 506)
+++ branches/vhffs_4.1/vhffs-backend/conf/vhffs.conf 2007-03-08 17:21:10 UTC (rev 507)
@@ -250,11 +250,13 @@
host = localhost
username = root
password = vhffs
+ mysqldump_path = /usr/bin/mysqldump
</mysql>
<postgresql>
host = localhost
username = vhffs
password = zepojf
+ pgdump_path = /usr/bin/pg_dump
</postgresql>
<subversion>
svnweb_url = "http://svnweb.hoster"
Modified: branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl 2007-03-08 11:44:10 UTC (rev 506)
+++ branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl 2007-03-08 17:21:10 UTC (rev 507)
@@ -34,21 +34,14 @@
# and put it on each group directory
#
-use lib "/usr/share/vhffs/api/";
-use Vhffs::Robots;
-
-
-#################
-#Config Stuff
-my $MYSQLDUMP_BINARY = "/usr/bin/mysqldump";
-#################
-
use strict;
+use lib "/usr/share/vhffs/api/";
use Vhffs::Main;
use Vhffs::User;
use Vhffs::Group;
use Vhffs::Functions;
use Vhffs::Services::Mysql;
+use Vhffs::Robots;
my $vhffs = init Vhffs::Main;
@@ -58,16 +51,13 @@
my $admin_dbuser = $vhffs->get_config->get_mysql_admin_username;
my $admin_dbpass = $vhffs->get_config->get_mysql_admin_pass;
my $admin_dbhost = $vhffs->get_config->get_mysql_admin_host;
+my $mysqldumppath = $vhffs->get_config->get_mysql_mysqldump_path;
my $obj;
my $group;
my $groupname;
-if( ! -x $MYSQLDUMP_BINARY )
-{
- print "Error, mysqldump is not present on this system\n";
- exit( -1 );
-}
+die "Error, mysqldump is not present on this system in path \"$mysqldumppath\"\n" unless( -x $mysqldumppath );
foreach $obj ( @{$objs} )
{
@@ -77,7 +67,7 @@
if( -d $dir )
{
my $file = $dir."/".$dbname.".mysql.dump";
- my $cmd = "$MYSQLDUMP_BINARY -u $admin_dbuser -h $admin_dbhost -p$admin_dbpass $dbname > $file";
+ my $cmd = "$mysqldumppath -u $admin_dbuser -h $admin_dbhost -p$admin_dbpass $dbname > $file";
system( $cmd );
#Change the chmod if the backup succeed
Added: branches/vhffs_4.1/vhffs-robots/src/dump_pgsql.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/dump_pgsql.pl 2007-03-08 11:44:10 UTC (rev 506)
+++ branches/vhffs_4.1/vhffs-robots/src/dump_pgsql.pl 2007-03-08 17:21:10 UTC (rev 507)
@@ -0,0 +1,86 @@
+#!/usr/bin/perl
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+#3. Neither the name of vhffs nor the names of its contributors
+# may be used to endorse or promote products derived from this
+# software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+########################################################
+# This robot make dump for each MySQL database
+# and put it on each group directory
+#
+
+use strict;
+use lib "/usr/share/vhffs/api/";
+use Vhffs::Main;
+use Vhffs::User;
+use Vhffs::Group;
+use Vhffs::Functions;
+use Vhffs::Services::Postgres;
+use Vhffs::Robots;
+
+my $vhffs = init Vhffs::Main;
+
+Vhffs::Robots::lock( $vhffs );
+
+my $objs = Vhffs::Services::Postgres::getall( $vhffs );
+my $admin_dbuser = $vhffs->get_config->get_pgsql_admin_username;
+my $admin_dbpass = $vhffs->get_config->get_pgsql_admin_pass;
+my $admin_dbhost = $vhffs->get_config->get_pgsql_admin_host;
+my $pgdumppath = $vhffs->get_config->get_pgsql_pgdump_path;
+
+my $obj;
+my $group;
+my $groupname;
+
+die "Error, pg_dump is not present on this system in path \"$pgdumppath\"\n" unless( -x $pgdumppath );
+
+foreach $obj ( @{$objs} )
+{
+ $groupname = Vhffs::Group::get_name_by_gid( $vhffs , $obj->get_ownergid );
+ my $dbname = $obj->get_dbname;
+ my $dir = Vhffs::Functions::hash_groupname( $groupname , $vhffs );
+ if( -d $dir )
+ {
+ my $file = $dir."/".$dbname.".pgsql.dump";
+ my $cmd = "$pgdumppath -U $admin_dbuser -h $admin_dbhost -b -Fc -Z6 -f $file $dbname";
+ system( $cmd );
+
+ print $cmd."\n";
+
+ #Change the chmod if the backup succeed
+ if( -f $file )
+ {
+ chown( $obj->get_owneruid , $obj->get_ownergid , $file );
+ chmod( 0660 , $file );
+ }
+ }
+}
+
+Vhffs::Robots::unlock( $vhffs );
+
+exit 0;
Property changes on: branches/vhffs_4.1/vhffs-robots/src/dump_pgsql.pl
___________________________________________________________________
Name: svn:executable
+ *