diff --git a/python/spacewalk/satellite_tools/spacewalk-debug b/python/spacewalk/satellite_tools/spacewalk-debug index 20770fd0c9fd..6f93d08d8f51 100755 --- a/python/spacewalk/satellite_tools/spacewalk-debug +++ b/python/spacewalk/satellite_tools/spacewalk-debug @@ -332,8 +332,6 @@ echo " * querying schema version, database charactersets and database" if [ "$(spacewalk-cfg-get externaldb)" = "0" ] ; then if [ -f /usr/bin/smdba ] ; then /usr/bin/smdba space-overview > $DIR/db-control-report - elif [ -f /usr/bin/db-control ] && [ "$(spacewalk-cfg-get db_backend)" = "postgresql" ] ; then - /usr/bin/db-control report > $DIR/db-control-report fi fi diff --git a/web/conf/rhn_dobby.conf b/web/conf/rhn_dobby.conf deleted file mode 100644 index 51710d453132..000000000000 --- a/web/conf/rhn_dobby.conf +++ /dev/null @@ -1,26 +0,0 @@ -sid = susemanager - -sysdba_username = sys -sysdba_password = manager - -oracle_home = /opt/apps/oracle/product/11gR2/dbhome_1 -data_dir_format = /opt/apps/oracle/oradata/embedded -hot_backup_dir_format = -archive_dir_format = /opt/apps/oracle/flash_recovery_area/embedded - -normal_username = susemanager -normal_password = susemanager - -remote_dsn = - -pg_data_dir_format = /var/lib/pgsql/data - -oracle_user = oracle -postgresql_user = postgres - -db_backend = -db_host = -db_port = -db_name = -db_user = -db_password = diff --git a/web/modules/Makefile b/web/modules/Makefile index 7ef5c8faf477..290e2a37c689 100644 --- a/web/modules/Makefile +++ b/web/modules/Makefile @@ -3,7 +3,7 @@ TOP = .. -SUBDIRS = pxt rhn dobby +SUBDIRS = pxt rhn include $(TOP)/Makefile.defs # whitespace change to test checkin diff --git a/web/modules/dobby/Changes b/web/modules/dobby/Changes deleted file mode 100644 index 8b137891791f..000000000000 --- a/web/modules/dobby/Changes +++ /dev/null @@ -1 +0,0 @@ - diff --git a/web/modules/dobby/Dobby.pm b/web/modules/dobby/Dobby.pm deleted file mode 100644 index 0a653d155daa..000000000000 --- a/web/modules/dobby/Dobby.pm +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -# stub module, mainly for $VERSION and any C stuff for later -package Dobby; - -use strict; - -our $VERSION = '0.01'; - -1; diff --git a/web/modules/dobby/Dobby/BackupLog.pm b/web/modules/dobby/Dobby/BackupLog.pm deleted file mode 100644 index 2ab11e3a89b0..000000000000 --- a/web/modules/dobby/Dobby/BackupLog.pm +++ /dev/null @@ -1,357 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# -use strict; -package Dobby::BackupLog; -use RHN::SimpleStruct; -use Storable qw/freeze thaw/; -## Ideally we would use XML::Simple but its not available on a Sat -## so we just use DOM to read/write this object to XML so it can -## be stored and reloaded from disk in a Perl indpendant format. -use XML::LibXML; - -our @ISA = qw/RHN::SimpleStruct/; -our @simple_struct_fields = qw/start finish sid tablespaces archive_logs control_file type cold_files cold_dirs base_dir/; - -# UGLY HACK for now; use Storable instead of a real data structure. -# ugh. - -sub parse { - my $class = shift; - my $restore_log = shift; - - my $parser = XML::LibXML -> new(); - my $doc = undef; - my $log = undef; - - eval { $doc = $parser->parse_file($restore_log); }; - if ($@) { - local * FH; - open FH, '<', $restore_log or die "open $restore_log: $!"; - my $contents = join("", ); - close FH; - $log = thaw($contents); - } - else - { - $log = fromXml($doc); - } - - return $log; -} - -#fill out the object with the values -#from the XML Dom. -sub fromXml() { - my $doc = shift; - my $log = new Dobby::BackupLog(); - - $log->sid(getTextValue($doc,'sid')); - $log->start(getTextValue($doc,'start')); - $log->type(getTextValue($doc,'type')); - $log->finish(getTextValue($doc,'finish')); - # this may fail on 5.4- dumps, it is safe to ignore it - eval { $log->base_dir(getTextValue($doc,'basedir')); }; - - - foreach my $fileentry ($doc->getElementsByTagName('fileentry')){ - my $fe = new Dobby::BackupLog::FileEntry(); - $log->add_cold_file($fe->fromXml($fileentry)); - } - - foreach my $direntry ($doc->getElementsByTagName('direntry')){ - my $de = new Dobby::BackupLog::DirEntry(); - $log->add_cold_file($de->fromXml($direntry)); - } - - foreach my $tablespaceentry ($doc->getElementsByTagName('tablespaceentry')){ - my $te = new Dobby::BackupLog::TablespaceEntry(); - $log->add_tablespace_entry($te->fromXml($tablespaceentry)); - } - - return $log; -} - -# Convert object to XML -sub toXml { - my $self = shift; - - my $doc = XML::LibXML::Document->new( "1.0", "UTF-8"); - my $root = $doc->createElement('backuplog'); - my $sid = $doc->createElement('sid'); - addTextValue($sid, $doc, $self->start); - my $start = $doc->createElement('start'); - addTextValue($start, $doc, $self->start); - my $control_file = $doc->createElement('controlfile'); - addTextValue($control_file, $doc, $self->control_file); - my $type = $doc->createElement('type'); - addTextValue($type, $doc, $self->type); - my $finish = $doc->createElement('finish'); - addTextValue($finish, $doc, $self->finish); - my $base_dir = $doc->createElement('basedir'); - addTextValue($base_dir, $doc, $self->base_dir); - - my $archive_logs = $doc->createElement('archivelogs'); - if (defined($self->archive_logs)) { - for my $archive_log (@{$self->archive_logs}) { - my $alog = $doc->createElement('controlfile'); - $archive_logs-> appendChild($alog); - } - } - - my $cold_files = $doc->createElement('coldfiles'); - if (defined($self->cold_files)) { - for my $file_entry (@{$self->cold_files}) { - $cold_files-> appendChild($file_entry->toXml($doc)); - } - } - my $cold_dirs = $doc->createElement('colddirs'); - if (defined($self->cold_dirs)) { - for my $dir_entry (@{$self->cold_dirs}) { - $cold_dirs-> appendChild($dir_entry->toXml($doc)); - } - } - - my $tablespaces = $doc->createElement('tablespaces'); - if (defined($self->tablespaces)) { - for my $tablespace_entry (@{$self->tablespaces}) { - $tablespaces-> appendChild($tablespace_entry->toXml($doc)); - } - } - - $root->appendChild($cold_files); - $root->appendChild($cold_dirs); - $root->appendChild($tablespaces); - $root->appendChild($sid); - $root->appendChild($start); - $root->appendChild($control_file); - $root->appendChild($type); - $root->appendChild($finish); - $root->appendChild($base_dir); - - my $retval = $root->toString . "\n"; - return $retval; - - -} - -## Util functions for XML processing -sub addTextValue { - my $node = shift; - my $doc = shift; - my $value = shift; - if (not defined $value) { - $value = ""; - } - my $textNode = $doc->createTextNode($value); - $node->appendChild($textNode); -} -sub getTextValue { - my $doc = shift; - my $tag = shift; - return $doc->getElementsByTagName($tag)->item(0)->getFirstChild->nodeValue; -} - -sub serialize { - my $self = shift; - my $dest = shift; - - local * FH; - open FH, '>', $dest or die "open $dest: $!"; - print FH $self->toXml(); - close FH; -} - -sub add_tablespace_entry { - my $self = shift; - - my $tablespaces = $self->tablespaces; - push @$tablespaces, @_; - $self->tablespaces($tablespaces); -} - -sub add_cold_file { - my $self = shift; - - foreach my $file (@_) { - if ($file->isa("Dobby::BackupLog::FileEntry")) { - my $cold_files = $self->cold_files; - push @$cold_files, @_; - $self->cold_files($cold_files); - } elsif ($file->isa("Dobby::BackupLog::DirEntry")) { - my $cold_dirs = $self->cold_dirs; - push @$cold_dirs, @_; - $self->cold_dirs($cold_dirs); - } - } -} - -package Dobby::BackupLog::TablespaceEntry; -use RHN::SimpleStruct; - -our @ISA = qw/RHN::SimpleStruct/; -our @simple_struct_fields = qw/name files start finish/; - -sub add_file_entry { - my $self = shift; - - my $files = $self->files; - push @$files, @_; - $self->files($files); -} - -#convert object to XML -sub toXml { - my $self = shift; - my $doc = shift; - - my $entry = $doc->createElement('tablespaceentry'); - my $name = $doc->createElement('name'); - Dobby::BackupLog::addTextValue($name, $doc, $self->name); - - my $start = $doc->createElement('start'); - Dobby::BackupLog::addTextValue($start, $doc, $self->start); - - my $finish = $doc->createElement('finish'); - Dobby::BackupLog::addTextValue($finish, $doc, $self->finish); - - $entry->appendChild($name); - $entry->appendChild($start); - $entry->appendChild($finish); - my $files = $doc->createElement('files'); - - if (defined($self->files)) { - for my $file_entry (@{$self->files}) { - my $file = $doc->createElement('file'); - Dobby::BackupLog::addTextValue($file, $doc, $file_entry); - $files->appendChild($file); - } - } - $entry->appendChild($files); - - return $entry; -} - -#fill out the object with the values -#from the XML Dom. -sub fromXml { - my $self = shift; - my $element = shift; - - $self->name(Dobby::BackupLog::getTextValue($element, 'name')); - $self->start(Dobby::BackupLog::getTextValue($element, 'start')); - $self->finish(Dobby::BackupLog::getTextValue($element, 'finish')); - - foreach my $fileelement ($element->getElementsByTagName('file')){ - $self->add_file_entry($fileelement->getFirstChild->nodeValue); - } - - return $self; -} - - - -package Dobby::BackupLog::FileEntry; -use RHN::SimpleStruct; - -our @ISA = qw/RHN::SimpleStruct/; -our @simple_struct_fields = qw/start finish from to digest compressed_size original_size/; - -#convert the object to XML -sub toXml { - my $self = shift; - my $doc = shift; - - my $entry = $doc->createElement('fileentry'); - my $originalsize = $doc->createElement('originalsize'); - Dobby::BackupLog::addTextValue($originalsize, $doc, $self->original_size); - - my $compressedsize = $doc->createElement('compressedsize'); - Dobby::BackupLog::addTextValue($compressedsize, $doc, $self->compressed_size); - - my $start = $doc->createElement('start'); - Dobby::BackupLog::addTextValue($start, $doc, $self->start); - - my $digest = $doc->createElement('digest'); - Dobby::BackupLog::addTextValue($digest, $doc, $self->digest); - - my $to = $doc->createElement('to'); - Dobby::BackupLog::addTextValue($to, $doc, $self->to); - - my $from = $doc->createElement('from'); - Dobby::BackupLog::addTextValue($from, $doc, $self->from); - - my $finish = $doc->createElement('finish'); - Dobby::BackupLog::addTextValue($finish, $doc, $self->finish); - - $entry->appendChild($originalsize); - $entry->appendChild($compressedsize); - $entry->appendChild($start); - $entry->appendChild($digest); - $entry->appendChild($to); - $entry->appendChild($from); - $entry->appendChild($finish); - - return $entry; -} - -#fill out the object with the values -#from the XML Dom. -sub fromXml { - my $self = shift; - my $element = shift; - - $self->start(Dobby::BackupLog::getTextValue($element, 'start')); - $self->finish(Dobby::BackupLog::getTextValue($element, 'finish')); - $self->from(Dobby::BackupLog::getTextValue($element, 'from')); - $self->to(Dobby::BackupLog::getTextValue($element, 'to')); - $self->digest(Dobby::BackupLog::getTextValue($element, 'digest')); - $self->original_size(Dobby::BackupLog::getTextValue($element, 'originalsize')); - $self->compressed_size(Dobby::BackupLog::getTextValue($element, 'compressedsize')); - - return $self; -} - -package Dobby::BackupLog::DirEntry; -use RHN::SimpleStruct; - -our @ISA = qw/RHN::SimpleStruct/; -our @simple_struct_fields = qw/from/; - -#convert the object to XML -sub toXml { - my $self = shift; - my $doc = shift; - - my $entry = $doc->createElement('direntry'); - - my $from = $doc->createElement('from'); - Dobby::BackupLog::addTextValue($from, $doc, $self->from); - - $entry->appendChild($from); - - return $entry; -} - -#fill out the object with the values -#from the XML Dom. -sub fromXml { - my $self = shift; - my $element = shift; - - $self->from(Dobby::BackupLog::getTextValue($element, 'from')); - - return $self; -} -1; diff --git a/web/modules/dobby/Dobby/CLI.pm b/web/modules/dobby/Dobby/CLI.pm deleted file mode 100644 index b2133482c0ec..000000000000 --- a/web/modules/dobby/Dobby/CLI.pm +++ /dev/null @@ -1,87 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::CLI; -use Params::Validate; -use Carp; - -use Dobby::Log; - -Params::Validate::validation_options(strip_leading => "-"); - -sub new { - my $class = shift; - my $exec_name = shift; - - my $self = bless { executable_name => $exec_name }, $class; - - $self->register_mode(-command => "help", - -description => "Display command summary", - -handler => \&Dobby::CLI::command_help); - - return $self; -} - -sub register_mode { - my $self = shift; - my %params = validate(@_, { command => 1, description => 1, handler => 1 }); - - croak "Attempt to re-register existing command $params{command}" if exists $self->{modes}->{$params{command}}; - - $self->{modes}->{$params{command}} = \%params; -} - -sub invoke_command { - my $self = shift; - my $command = shift; - my @args = @_; - - $self->fatal("No such command '$command'; use 'help' to list available commands.") unless exists $self->{modes}->{$command}; - - $self->{executing_mode} = $command; - my $handler = $self->{modes}->{$command}->{handler}; - - $handler->($self, $command, @args); -} - -sub usage { - my $self = shift; - my $msg = shift; - - print STDERR sprintf("Usage: %s %s %s\n", $self->{executable_name}, $self->{executing_mode}, $msg); - exit 1; -} - -sub fatal { - my $self = shift; - my $msg = shift; - - print STDERR "$msg\n"; - exit 1; -} - -sub command_help { - my $self = shift; - my $command = shift; - my @args = @_; - - print "Available commands:\n"; - for my $command (sort keys %{$self->{modes}}) { - printf " %-10s - %s\n", $command, $self->{modes}->{$command}->{description}; - } -} - -1; diff --git a/web/modules/dobby/Dobby/CLI/BackupCommands.pm b/web/modules/dobby/Dobby/CLI/BackupCommands.pm deleted file mode 100644 index b8845ed81dcd..000000000000 --- a/web/modules/dobby/Dobby/CLI/BackupCommands.pm +++ /dev/null @@ -1,425 +0,0 @@ -# -# Copyright (c) 2008--2017 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::CLI::BackupCommands; - -use Carp; -use Dobby::Files; -use Dobby::BackupLog; -use English; -use File::Basename qw/basename dirname/; -use File::Spec; -use Filesys::Df; -use POSIX; - -use Dobby::DB; -use Dobby::Reporting; -use Dobby::CLI::MiscCommands; - -sub register_dobby_commands { - my $class = shift; - my $cli = shift; - - $cli->register_mode(-command => "backup", - -description => "Backup the SUSE Manager Database Instance", - -handler => \&command_backup); - $cli->register_mode(-command => "restore", - -description => "Restore the SUSE Manager Database Instance from backup", - -handler => \&command_restore); - $cli->register_mode(-command => "verify", - -description => "Verify an SUSE Manager Database Instance backup", - -handler => \&command_restore); - $cli->register_mode(-command => "examine", - -description => "Display information about an SUSE Manager Database Instance backup", - -handler => \&command_restore); - $cli->register_mode(-command => "online-backup", - -description => "Perform online backup of RHN Satellite database (PostgreSQL only)", - -handler => \&command_pg_online_backup); -} - -# returns $file cuted of prefix made from $cut_off_dir -sub cut_off_dir { - my ($file, $cut_off_dir) = @_; - $file =~ s/^$cut_off_dir//; - return $file; -} - -sub cut_dir { - my ($file, $cut_off_dir) = @_; - return dirname(cut_off_dir($file, $cut_off_dir)); -} - -sub directory_contents { - my ($cli, $dir, $cut_off_dir) = @_; - $cut_off_dir = $dir if not defined $cut_off_dir; - - my @files; - opendir DIR, $dir or $cli->fatal("opendir $dir: $!"); - my @dir_content = readdir DIR; - closedir DIR; - my @without_up_dir = grep {$_ ne '.' and $_ ne '..'} @dir_content; - foreach my $directory (grep { -d $_ } map { File::Spec->catfile($dir, $_) } @without_up_dir) { - push @files, directory_contents($cli, $directory, $cut_off_dir); - } - push @files, map {[$_, cut_dir($_, $cut_off_dir)]} grep { -f $_ } map { File::Spec->catfile($dir, $_) } @dir_content; - - if (@files) { - return @files; - } else { #directory is empty, return directory itself - return ([$dir, $cut_off_dir]) if ($dir ne $cut_off_dir); - } -} - -sub command_backup { - my $cli = shift; - my $command = shift; - my $backup_dir = shift; - $cli->usage("TARGET_DIR") unless $backup_dir; - - my $d = new Dobby::DB; - - my $logged_user = getpwuid($>); - $cli->fatal("Error: $backup_dir is not a writable directory by $logged_user.") unless -d $backup_dir and -w $backup_dir; - $cli->fatal("Database is running; please stop before running a cold backup.") if $d->instance_state ne 'OFFLINE'; - - my $source_dir = $d->data_dir; - my $backend = PXT::Config->get('db_backend'); - - my $log = new Dobby::BackupLog; - $log->type('cold'); - $log->sid($d->sid); - $log->start(time); - $log->base_dir($backup_dir); - - $|++; - print "Initiating cold backup of database ", $d->sid, "...\n"; - - my @files; - - if ($backend eq 'oracle') { - push @files, [$d->lk_file, '/']; - push @files, [$d->sp_file, '/']; - } - - for my $dir ($d->data_dir, $d->archive_log_dir) { - push @files, directory_contents($cli, $dir, $dir) if ($dir); - } - - for my $ret (@files) { - next unless $ret; - my ($file, $rel_dir) = @{$ret}; - my $file_entry = Dobby::Files->backup_file($rel_dir, $file, $backup_dir); - $log->add_cold_file($file_entry); - } - - $log->finish(time); - $log->serialize("$backup_dir/backup-log.dat"); - - print "Full cold backup complete.\n"; - - return 0; -} - -sub command_restore { - my $cli = shift; - my $command = shift; - my $restore_dir = shift; - - my $backend = PXT::Config->get('db_backend'); - my $cfg = new PXT::Config("dobby"); - $cli->usage("BACKUP") unless $restore_dir and -e $restore_dir; - my $restore_log = File::Spec->catfile($restore_dir, "backup-log.dat"); - - if ($backend eq 'postgresql' and -f $restore_dir) { - # online backup dump - return command_pg_restore($cli, $command, $restore_dir); - } elsif (not (-r $restore_log)) { - $cli->fatal("Error: restoration failed, unable to locate $restore_log"); - } - - my $d = new Dobby::DB; - print "Parsing backup log.\n"; - my $log = Dobby::BackupLog->parse($restore_log); - - if ($log->type ne 'cold') { - $cli->fatal("Error: backup not a cold backup."); - } - - if ($command eq 'verify') { - printf "Verifying backup from %s...\n", scalar localtime $log->start; - } - elsif ($command eq 'restore') { - $cli->fatal("Database is currently running; please stop it before restoring a backup.") if $d->instance_state ne 'OFFLINE'; - printf "Restoring backup from %s...\n", scalar localtime $log->start; - } - elsif ($command eq 'examine') { - printf "Backup made on %s:\n", scalar localtime $log->start; - } - else { - $cli->fatal("unknown subcommand of command_restore"); - } - - my @rename_queue; - my $error_count; - - my %seen_files; - my @existing_files; - if ($command eq 'restore') { - push @existing_files, directory_contents($cli, $d->data_dir); - push @existing_files, directory_contents($cli, $d->archive_log_dir) if $d->archive_log_dir; - } - - my $df = df($d->data_dir, "1024"); - my $available_space = $df->{bavail} * 1024; - - - my $required_space = 0; - for my $file_entry (@{$log->cold_files}) { - $required_space += $file_entry->original_size; - } - - if ($command eq 'restore' and $available_space < $required_space) { - print "Error: Not enough free space for restoration.\n"; - printf "Available: %7s\n", Dobby::CLI::MiscCommands->size_scale($available_space); - printf "Required : %7s\n", Dobby::CLI::MiscCommands->size_scale($required_space); - return 1; - } - - my $intended_username = $cfg->get("${backend}_user"); - my ($username, undef, $uid, $gid) = getpwnam($intended_username); - for my $file_entry (@{$log->cold_files}) { - # to and from reverse since their names come from the backup - # script itself. - - my ($src, $dst) = ($file_entry->to, $file_entry->from); - if ($log->base_dir) { - $src = File::Spec->catfile($restore_dir, cut_off_dir($src, $log->base_dir)); - } else { # old backups (prior spacewalk 1.8) do not have basedir and assume all in one dir - $src = File::Spec->catfile($restore_dir, basename($src)); - } - my ($digest, $missing); - - printf " %s", $src; - - my $err_msg; - $missing++ unless -e $src; - - if ($command eq 'verify') { - printf "..."; - $digest = Dobby::Files->gunzip_copy($src) unless $missing; - } - elsif ($command eq 'restore') { - # extract to temporary files to be renamed over originals once - # entire process succeeds. populate list of pending renames. - - my $tmpdst = $dst . ".tmp"; - - printf " -> %s...", $tmpdst; - if (not $missing) { - $digest = eval { Dobby::Files->gunzip_copy($src, $tmpdst, $uid, $gid) }; - if (not defined $digest and $@) { - $err_msg = $@; - } - } - - $seen_files{+$dst} = 1; - push @rename_queue, [ $tmpdst, $dst ]; - } - elsif ($command eq 'examine') { - # nop, messaging comes in below - } - - if ($missing) { - print " (MISSING)\n"; - $error_count++; - } - elsif ($err_msg) { - print "\n\nFatal error: $err_msg"; - $error_count++; - last; - } - elsif (defined $digest and $digest ne $file_entry->digest) { - printf " done. (ERROR: checksum mismatch)\n"; - $error_count++; - } - else { - if (defined $digest) { - print " done. Checksum verified.\n"; - } - else { - print "\n"; - } - } - } - - if ($command eq 'restore') { - if ($error_count) { - print "Cannot restore database, errors encountered. Please correct and re-attempt restoration.\n"; - - # now remove the .tmp files we made, ignoring errors - unlink $_->[0] for @rename_queue; - return 1; - } - else { - print "Extraction and verification complete, renaming files... "; - for my $entry (@rename_queue) { - rename $entry->[0] => $entry->[1] or warn "Rename $entry->[0] => $entry->[1] error: $!"; - system("/sbin/restorecon", $entry->[1]); - - } - print "done.\n"; - - # now, remove any archive logs that were not actually restored - # in the backup set. if we've seen it before, then we overwrote - # it, so the contents are correct. - print "Removing unnecessary files... "; - for my $ret (@existing_files) { - next unless $ret; - my ($file, $rel_dir) = @{$ret}; - next if exists $seen_files{+$file}; - - if (-d $file) { - rmdir $file or warn "Error removing $file: $!"; - } else { - unlink $file or warn "Error unlinking $file: $!"; - } - } - print "done.\n"; - - print "Restoring empty directories... "; - if ($log->cold_dirs) { - for my $dir_entry (@{$log->cold_dirs}) { - if (my @dirs = File::Path::mkpath($dir_entry->from, 0, 0700)) { - chown $uid, $gid, @dirs; - } - } - } - print "done.\n"; - - print "Restoration complete, you may now start the database.\n"; - } - } - elsif ($command eq 'examine' or $command eq 'verify') { - if ($error_count) { - return 1; - } else { - return 0; - } - } - return 0; -} - -sub command_pg_online_backup { - my ($cli, $command, $file) = @_; - $cli->usage("FILE") unless $file; - - my $backup_dir = dirname $file; - - my $backend = PXT::Config->get('db_backend'); - $cli->fatal("Error: This backup method works only with PostgreSQL.") unless ($backend eq 'postgresql'); - my $cfg = new PXT::Config("dobby"); - my @rec = getpwnam($cfg->get("postgresql_user")); - $EUID = $rec[2]; - $UID = $rec[2]; - $cli->fatal("Error: $backup_dir is not a writable directory for user $rec[0].") unless -d $backup_dir and -w $backup_dir; - $cli->fatal("Error: Backup file $file already exists in $file.") if -f $file; - - print "Backing up to file $file.\n"; - my $ret = system(@{Dobby::CLI::MiscCommands::pg_version('pg_dump')}, "--blobs", "--clean", "-Fc", "-v", "-Z7", "--file=$file", PXT::Config->get('db_name')); - if ($ret == 0) { - print "Backup complete.\n"; - return 0; - } - my $exitsignal = $ret & 0xff; - my $exitstatus = ($ret >> 8) & 0xff; - if ($exitsignal == 0) { - return $exitstatus; - } - print "Command terminated on signal $exitsignal\n"; - return 1; -} - -sub command_pg_restore { - my ($cli, $command, $file) = @_; - $cli->usage("FILE") unless $file; - - $cli->fatal("Error: restoration failed, unable to locate $file") unless -r $file; - - my $backend = PXT::Config->get('db_backend'); - $cli->fatal("Error: This backup method works only with PostgreSQL.") unless ($backend eq 'postgresql'); - my @info = qx{$restore_command}; - my $cfg = new PXT::Config("dobby"); - my @rec = getpwnam($cfg->get("postgresql_user")); - $EUID = $rec[2]; - $UID = $rec[2]; - $cli->fatal("Error: file $file is not readable by user $rec[0]") unless -r $file; - - my $service_status = system('service ' . Dobby::CLI::MiscCommands::pg_version('service') . ' status >/dev/null 2>&1'); - $cli->fatal("PostgreSQL database is not running.\n" - ."Run 'service " . Dobby::CLI::MiscCommands::pg_version('service') . " start' to start it.") unless $service_status == 0; - - my $user = PXT::Config->get("db_user"); - my $password = PXT::Config->get("db_password"); - my $schema = PXT::Config->get("db_name"); - my $dsn = "dbi:Pg:dbname=$schema"; - my $dbh = RHN::DB->direct_connect($dsn); - - no warnings 'redefine'; - sub Spacewalk::Setup::system_debug { - system @_; - } - - my $is_active = (Dobby::Reporting->active_sessions_postgresql($dbh, $schema) > 1); - if ($is_active) { - $cli->fatal("There are running spacewalk services which are using database.\n" - . "Run 'spacewalk-service --exclude=" . Dobby::CLI::MiscCommands::pg_version('service') . " stop' to stop them."); - exit 1; - } - - { - my @schemas = ('rpm', 'rhn_exception', 'rhn_config', 'rhn_server', 'rhn_entitlements', 'rhn_bel', - 'rhn_cache', 'rhn_channel', 'rhn_config_channel', 'rhn_org', 'rhn_user', 'logging', 'public'); - - local $dbh->{RaiseError} = 0; - local $dbh->{PrintError} = 1; - local $dbh->{PrintWarn} = 0; - local $dbh->{AutoCommit} = 1; - - foreach my $schema (@schemas) { - $dbh->do("drop schema if exists $schema cascade;"); - } - $dbh->do("create schema public authorization postgres;"); - } - - system(@{Dobby::CLI::MiscCommands::pg_version('droplang')}, 'plpgsql', PXT::Config->get('db_name')); - system(@{Dobby::CLI::MiscCommands::pg_version('droplang')}, 'pltclu', PXT::Config->get('db_name')); - - print "** Restoring from file $file.\n"; - my $ret = system(@{Dobby::CLI::MiscCommands::pg_version('pg_restore')}, "-Fc", "--jobs=2", "--dbname=".PXT::Config->get('db_name'), $file ); - if ($ret == 0) { - print "Restoration complete.\n"; - return 0; - } - my $exitsignal = $ret & 0xff; - my $exitstatus = ($ret >> 8) & 0xff; - if ($exitsignal == 0) { - return $exitstatus; - } - print "Command terminated on signal $exitsignal\n"; - return 1; -} - -1; diff --git a/web/modules/dobby/Dobby/CLI/MaintCommands.pm b/web/modules/dobby/Dobby/CLI/MaintCommands.pm deleted file mode 100644 index 591e9caf4b98..000000000000 --- a/web/modules/dobby/Dobby/CLI/MaintCommands.pm +++ /dev/null @@ -1,189 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::CLI::MaintCommands; - -use Carp; - -use Filesys::Df; -use File::Basename; -use Dobby::DB; -use Dobby::CLI::MiscCommands; - -sub register_dobby_commands { - my $class = shift; - my $cli = shift; - - $cli->register_mode(-command => "extend", - -description => "Increase the SUSE Manager Database Instance tablespace", - -handler => \&command_extend); - $cli->register_mode(-command => "gather-stats", - -description => "Gather statistics on SUSE Manager Database database objects", - -handler => \&gather_stats); - $cli->register_mode(-command => "shrink-segments", - -description => "Shrink SUSE Manager Database database segments", - -handler => \&shrink_segments); -} - -sub command_extend { - my $cli = shift; - my $command = shift; - my $ts = shift; - $ts = uc($ts); - - my $backend = PXT::Config->get('db_backend'); - $cli->fatal("Error: This command works only with Oracle.") unless ($backend eq 'oracle'); - - $cli->usage("TABLESPACE") unless $ts; - - my $d = new Dobby::DB; - - if (not $d->database_started) { - print "Error: The database must be running to extend a tablespace.\n"; - return 1; - } - - my @files = $d->tablespace_datafiles($ts); - my $f = pop(@files); - - if (!$f) { - print "Error: Invalid tablespace name '$ts' specified.\n"; - return 1; - } - - my $file = $f->{FILENAME}; - my $status = $f->{STATUS}; - my $bytes = $f->{BYTES}; - my $ftype = $f->{FILETYPE}; - - #Check here for available space - my $df = df($d->data_dir, "1024"); - my $available_space = $df->{bavail} * 1024; - - if ($available_space < $bytes) { - print "Error: Not enough free space to extend tablespace.\n"; - printf "Available: %7s\n", Dobby::CLI::MiscCommands->size_scale($available_space); - printf "Required : %7s\n", Dobby::CLI::MiscCommands->size_scale($bytes); - return 1; - } - - - print "Extending $ts... "; - my $fn = next_filename($cli, $file); - my $size = $bytes / 1024; - $d->tablespace_extend($ts, $ftype, $fn, "$size K"); - print "done.\n"; - - return 0; -} - -sub next_filename { - my $cli = shift; - my $fn = shift; - my $next; - - my $dir = dirname($fn); - my $base = basename($fn); - $base =~ /^(.*)(\.dbf)/; - my $root = $1; - my $suffix = $2; - if ($root =~ /(.*_)(\d+)/) { - my $seq = $2; - $seq++; - $next = sprintf("%s/%s%2.2i%s", $dir, $1, $seq, $suffix); - } - else { - $next = sprintf("%s/%s_%2.2i%s", $dir, $root, 2, $suffix); - } - return $next; -} - - -sub gather_stats { - my $cli = shift; - my $command = shift; - my $pct = shift; - - my $d = new Dobby::DB; - - $pct = 15 if not defined($pct); - $cli->usage("PERCENT") unless 0 < $pct and $pct <=100; - my $backend = PXT::Config->get('db_backend'); - - if (not $d->database_started) { - print "Error: The database must be running to gather statistics.\n"; - return 1; - } - - print "Gathering statistics...\n"; - print "WARNING: this may be a very slow process.\n"; - if($backend eq 'postgresql') { - $d->gather_database_stats_postgresql($pct); - } else { - $d->gather_database_stats_oracle($pct); - } - print "done.\n"; - - return 0; -} - -sub shrink_segments { - my $cli = shift; - - my $backend = PXT::Config->get('db_backend'); - - my $d = new Dobby::DB; - - if (not $d->database_started) { - print "Error: The database must be running to shrink segments.\n"; - return 1; - } - - if ($backend eq 'oracle') { - print "Running segment advisor to find out shrinkable segments...\n"; - } - print "WARNING: this may be a slow process.\n"; - if ($backend eq 'oracle') { - $d->segadv_runtask(); - my %msg = ( - 'AUTO' => "Shrinking recomended segments...\n", - 'MANUAL' => "Segments in non-shrinkable tablespace...\n", - ); - my %printed = ( - 'AUTO' => 0, - 'MANUAL' => 0, - ); - - for my $rec (Dobby::Reporting->segadv_recomendations($d)) { - if (not $printed{$rec->{SEGMENT_SPACE_MANAGEMENT}}) { - print $msg{$rec->{SEGMENT_SPACE_MANAGEMENT}}; - $printed{$rec->{SEGMENT_SPACE_MANAGEMENT}}++; - } - printf "%-32s %7s reclaimable\n", $rec->{SEGMENT_NAME}, - Dobby::CLI::MiscCommands->size_scale($rec->{RECLAIMABLE_SPACE}); - if ($rec->{SEGMENT_SPACE_MANAGEMENT} eq 'AUTO') { - $d->shrink_segment($rec); - } - } - } else { - $d->shrink_segments_postgresql(); - } - - print "done.\n"; - return 0; -} - -1; diff --git a/web/modules/dobby/Dobby/CLI/MiscCommands.pm b/web/modules/dobby/Dobby/CLI/MiscCommands.pm deleted file mode 100644 index cad45e3d723e..000000000000 --- a/web/modules/dobby/Dobby/CLI/MiscCommands.pm +++ /dev/null @@ -1,348 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::CLI::MiscCommands; - -use Carp; -use English; - -use Dobby::DB; -use Dobby::Reporting; - -sub register_dobby_commands { - my $class = shift; - my $cli = shift; - - $cli->register_mode(-command => "stop", - -description => "Stop the SUSE Manager Database Instance", - -handler => \&command_startstop); - $cli->register_mode(-command => "start", - -description => "Start the SUSE Manager Database Instance", - -handler => \&command_startstop); - - $cli->register_mode(-command => "status", - -description => "Show database status", - -handler => \&command_status); - $cli->register_mode(-command => "report", - -description => "Show database space report", - -handler => \&command_report); - $cli->register_mode(-command => "tablesizes", - -description => "Show space report for each table", - -handler => \&command_tablesizes); - $cli->register_mode(-command => "report-stats", - -description => "Show tables with stale or empty statistics", - -handler => \&command_reportstats); - $cli->register_mode(-command => "reset-password", - -description => "Reset the user password and unlock account", - -handler => \&command_resetpassword); - $cli->register_mode(-command => "get-optimizer", - -description => "Show database optimizer mode (Oracle only)", - -handler => \&command_get_optimizer); - $cli->register_mode(-command => "set-optimizer", - -description => "Set database optimizer mode (Oracle only)", - -handler => \&command_set_optimizer); -} - -my %pg_version = (); -sub pg_version { - if (not %pg_version) { - if (system("rpm -q postgresql92-postgresql-server >/dev/null 2>&1") == 0) { - $pg_version{'service'} = 'postgresql92-postgresql'; - $pg_version{'pg_dump'} = ['/usr/bin/scl', 'enable', 'postgresql92', '--', 'pg_dump']; - $pg_version{'pg_restore'} = ['/usr/bin/scl', 'enable', 'postgresql92', '--', 'pg_restore']; - $pg_version{'droplang'} = ['/usr/bin/scl', 'enable', 'postgresql92', '--', 'droplang']; - } else { - $pg_version{'service'} = 'postgresql'; - $pg_version{'pg_dump'} = ['/usr/bin/pg_dump']; - $pg_version{'pg_restore'} = ['/usr/bin/pg_restore']; - $pg_version{'droplang'} = ['/usr/bin/droplang']; - } - } - my ($key) = @_; - return $pg_version{$key}; -} - -my %msgs = - ( OPEN => "The database is running and accepting connections.", - OFFLINE => "The database is offline.", - MOUNTED => "The database is running but not accepting connections.", - STOPPING => "The database is in the process of shutting down.", - ); - -sub command_startstop { - my $cli = shift; - my $command = shift; - - my $d = new Dobby::DB; - my $backend = PXT::Config->get('db_backend'); - - my $retval = 0; - my $state = 'NULL'; - - if ($command eq 'start') { - if ($d->instance_state ne 'OFFLINE') { - print "Database already running.\n"; - } - else { - if ($backend eq 'postgresql') { - system("/sbin/service", pg_version('service'), "start"); - } else { - print "Starting database... "; - $d->database_startup; - $d->listener_startup; - print "done.\n"; - } - $state = $d->instance_state; - if ($state ne 'OPEN') { - $retval = 1; - print "Unable to connect to database to determine status. If database service\n"; - print "started successfully, check configuration in rhn.conf.\n"; - } - } - } - elsif ($command eq 'stop') { - if ($d->instance_state eq 'OFFLINE') { - print "Database already shut down.\n"; - } - else { - if ($backend eq 'postgresql') { - system("/sbin/service", pg_version('service'), "stop"); - $state = $d->instance_state; - if ($state ne 'OFFLINE') { - $retval = 1; - } - } else { - print "Shutting down database"; - $d->listener_shutdown; - $d->database_shutdown("immediate"); - my $i = 5; - $| = 1; - while (($i-- > 0) and ($d->instance_state ne 'OFFLINE')) { - sleep 1; - print "."; - } - $state = $d->instance_state; - if ($state ne 'OFFLINE') { - $retval = 1; - print " fail.\n"; - } - else { - print " done.\n"; - } - } - if ($retval != 0) { - print "Database failed to stop. "; - if (exists $msgs{$state}) { - print "$msgs{$state}\n"; - } - else { - print "Unknown database state '$state'\n"; - } - } - } - } - else { - croak "Unknown command '$command' not in (start, stop)"; - } - return $retval; -} - -sub command_status { - my $cli = shift; - - my $d = new Dobby::DB; - my $state = $d->instance_state; - - if (exists $msgs{$state}) { - print "$msgs{$state}\n"; - } - else { - print "Error: unknown database state '$state'\n"; - } - - return ($state eq 'OPEN' ? 0 : 1); -} - -# input is a number of bytes -# output is human-readable string -sub size_scale { - my $class = shift; - my $n = shift; - my @prefixes = qw/B K M G T/; - - while ($n > 1024 and @prefixes > 1) { - shift @prefixes; - $n = int(10 * $n / 1024)/10; - } - - return "$n$prefixes[0]"; -} - -sub command_report { - my $cli = shift; - - my $d = new Dobby::DB; - if (not $d->database_started) { - print "Error: The database must be running to get a space report.\n"; - return 1; - } - - my $indent = " "; - my $backend = PXT::Config->get('db_backend'); - - if ($backend eq 'postgresql') { - my $fmt = "%-24s %7s\n"; - my $schema = PXT::Config->get('db_name'); - printf $fmt, "Tablespace", "Size"; - my $ret = (Dobby::Reporting->tablespace_overview_postgresql($d, $schema))[0]; - printf $fmt, $schema, $ret->{'TOTAL_SIZE'}; - } else { - my $fmt = "%-24s %7s %7s %7s %5s%%\n"; - printf $fmt, "Tablespace", "Size", "Used", "Avail", "Use"; - - my $class = __PACKAGE__; - for my $ts (sort { $a->{NAME} cmp $b->{NAME} } Dobby::Reporting->tablespace_overview_oracle($d)) { - $ts->{FREE_BYTES} = $ts->{TOTAL_BYTES} - ($ts->{USED_BYTES} or 0) unless $ts->{FREE_BYTES}; - $ts->{USED_BYTES} = $ts->{TOTAL_BYTES} - ($ts->{FREE_BYTES} or 0) unless $ts->{USED_BYTES}; - printf $fmt, - $ts->{NAME}, - $class->size_scale($ts->{TOTAL_BYTES}), - $class->size_scale($ts->{USED_BYTES}), - $class->size_scale($ts->{FREE_BYTES}), - sprintf("%.0f", 100 * ($ts->{USED_BYTES} / $ts->{TOTAL_BYTES})); - } - } - return 0; -} - -sub command_tablesizes { - my $cli = shift; - - my $d = new Dobby::DB; - if (not $d->database_started) { - print "Error: The database must be running to get a space report.\n"; - return 1; - } - - my $indent = " "; - my $backend = PXT::Config->get('db_backend'); - my $class = __PACKAGE__; - - if ($backend eq 'postgresql') { - my $fmt = "%-32s %12s %12s %21s\n"; - printf $fmt, "Tables", "Planner Size", "Real Size", "Real Size+Toasts+Idx"; - - for my $ts (sort { $a->{NAME} cmp $b->{NAME} } Dobby::Reporting->table_size_overview_postgresql($d)) { - printf $fmt, $ts->{'NAME'}, $ts->{'PLANER'}, $ts->{'SIZE'}, $ts->{'TOTAL_SIZE'}; - } - } else { - my $fmt = "%-32s %7s\n"; - printf $fmt, "Tables", "Size"; - - my $total = 0; - for my $ts (sort { $a->{NAME} cmp $b->{NAME} } Dobby::Reporting->table_size_overview_oracle($d)) { - printf $fmt, - $ts->{NAME}, $class->size_scale($ts->{TOTAL_BYTES}); - $total += $ts->{TOTAL_BYTES}; - } - - printf $fmt, "-" x 32, "-" x 7; - printf $fmt, "Total", $class->size_scale($total); - } - return 0; -} - -sub command_reportstats { - my ($cli, $command, $days) = @_; - my $d = new Dobby::DB; - if (not $d->database_started) { - print "Error: The database must be running to get a statistics report.\n"; - return 1; - } - my $backend = PXT::Config->get('db_backend'); - $days = 1 unless (defined $days); - my $stats = ($backend eq 'postgresql') ? $d->report_database_stats_postgresql($days) : $d->report_database_stats_oracle; - for my $i (sort keys %$stats) { - print "Tables with $i statistics: $stats->{$i}\n"; - } - return 0; -} - -sub command_resetpassword { - my $cli = shift; - - my $d = new Dobby::DB; - - if (not $d->database_started) { - print "Error: The database must be running to reset the user password.\n"; - return 1; - } - - my $result = $d->password_reset(); - if ($result) { - print "Password reset for database user $result\n"; - } else { - print "Failed to reset password\n"; - return 1; - } - return 0; -} - -sub command_get_optimizer { - my $cli = shift; - - my $backend = PXT::Config->get('db_backend'); - $cli->fatal("Error: This command works only with Oracle.") unless ($backend eq 'oracle'); - - my $d = new Dobby::DB; - - if (not $d->database_started) { - print "Error: The database must be running to get optimizer mode settings.\n"; - return 1; - } - - my $mode = $d->get_optimizer_mode(); - print "Database optimizer mode: $mode\n"; - - if ($mode !~ /^.+ROWS.*$/) { - print "\nWarning: your database is using unsupported optimizer mode.\n"; - print "Use \"db-control set-optimizer\" to restore supported optimzer settings.\n"; - } - - return 0; -} - -sub command_set_optimizer { - my $cli = shift; - - my $backend = PXT::Config->get('db_backend'); - $cli->fatal("Error: This command works only with Oracle.") unless ($backend eq 'oracle'); - - my $d = new Dobby::DB; - - if (not $d->database_started) { - print "Error: The database must be running to set optimizer mode.\n"; - return 1; - } - - my $mode = 'ALL_ROWS'; - $d->set_optimizer_mode($mode); - print "Database optimizer mode set to $mode\n"; - - return 0; -} - -1; diff --git a/web/modules/dobby/Dobby/DB.pm b/web/modules/dobby/Dobby/DB.pm deleted file mode 100644 index 23b4a47509e3..000000000000 --- a/web/modules/dobby/Dobby/DB.pm +++ /dev/null @@ -1,519 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::DB; -use RHN::DB; -use RHN::DBI (); -use PXT::Config; -use Dobby::Log; - -use IO::Select (); -use IPC::Open2 (); - -use Carp qw/carp croak/; - -use File::Spec::Functions; -use IO::Handle; - -$PXT::Config::default_config = new PXT::Config('dobby'); - -sub new { - my $class = shift; - - my $self = bless { }, $class; - - return $self; -} - -sub config { - my $self = shift; - - return $self->{config} if $self->{config}; - - $self->{config} = new PXT::Config("dobby"); - return $self->{config}; -} - -sub DESTROY { - my $self = shift; - - $self->{sysdbh}->disconnect if $self->{sysdbh}; - $self->{dbh}->disconnect if $self->{dbh}; -} - -sub sid { - my $self = shift; - - # maybe make this smarter someday - return $self->config->get('sid'); -} - -sub normal_user { - my $self = shift; - - return $self->config->get('normal_username'); -} - -sub database_started { - my $self = shift; - - my $dbh = eval { $self->sysdba_connect }; - if (not $dbh and PXT::Config->get('db_backend') eq 'postgresql') { - my $dsn = "dbi:Pg:dbname=".PXT::Config->get("db_name"); - $dbh = eval { RHN::DB->direct_connect($dsn, "postgres") }; - } - return $dbh ? 1 : 0; -} - -sub data_dir { - my $self = shift; - my $backend = PXT::Config->get('db_backend'); - return ($backend eq 'postgresql') ? $self->config->get("pg_data_dir_format") : - sprintf($self->config->get("data_dir_format"), $self->sid); -} - -sub archive_log_dir { - my $self = shift; - my $backend = PXT::Config->get('db_backend'); - return ($backend eq 'postgresql') ? undef : - sprintf($self->config->get("archive_dir_format"), $self->sid); -} - -sub oracle_homedir_relative { - my $self = shift; - my $path = shift; - - my @pwent = getpwuid($>); - - return File::Spec->catfile($pwent[7], $path); -} - -sub sp_file { - my $self = shift; - - return $self->oracle_homedir_relative("product/11gR2/dbhome_1/dbs/spfileembedded.ora"); -} - -sub lk_file { - my $self = shift; - - return $self->oracle_homedir_relative("product/11gR2/dbhome_1/dbs/lkSUSEMANA"); -} - -sub tablespaces { - my $self = shift; - my $ts = shift; - - my $dbh = $self->sysdba_connect; - my $sth = $dbh->prepare(<execute; - - return $sth->fullfetch_hashref; -} - -sub tablespace_datafiles { - my $self = shift; - my $ts = shift; - - my $dbh = $self->sysdba_connect; - - my $sth = $dbh->prepare(<execute_h(ts => $ts); - return $sth->fullfetch_hashref; -} - -sub tablespace_extend { - my $self = shift; - my $ts = shift; - my $ft = shift; - my $fn = shift; - my $sz = shift; - - my $dbh = $self->sysdba_connect; - $dbh->do("ALTER TABLESPACE $ts ADD $ft '$fn' SIZE $sz REUSE"); -} - -sub report_database_stats_postgresql { - my ($self, $days) = @_; - - my $stats = { - stale => 0, - empty => 0, - }; - my $dbh = $self->connect; - - # sanitize input - $days += 0; - my $sth = $dbh->prepare(<execute; - ($stats->{'stale'}) = $sth->fetchrow_array; - - $sth = $dbh->prepare(<execute; - ($stats->{'empty'}) = $sth->fetchrow_array; - - return $stats; -} - -sub report_database_stats_oracle { - my $self = shift; - - my $stats = { - stale => 0, - empty => 0, - }; - my $dbh = $self->connect; - - my $sth = $dbh->prepare(<'LIST STALE', objlist=>objs); - :stale := objs.count(); - dbms_stats.gather_schema_stats(NULL, options=>'LIST EMPTY', objlist=>objs); - :empty := objs.count(); -end; -RSTATS - $sth->bind_param_inout(':stale', \$stats->{stale}, 16); - $sth->bind_param_inout(':empty', \$stats->{empty}, 16); - $sth->execute(); - - return $stats; -} - -sub gather_database_stats_oracle { - my $self = shift; - my $pct = shift; - - my $dbh = $self->connect; - $dbh->do("begin dbms_stats.gather_schema_stats(NULL, ESTIMATE_PERCENT=> $pct, DEGREE=>DBMS_STATS.DEFAULT_DEGREE, CASCADE=>TRUE); end;"); -} - -sub gather_database_stats_postgresql { - my $self = shift; - - my $dbh = $self->connect; - $dbh->do("ANALYZE"); -} - -sub segadv_runtask { - my $self = shift; - - my $dbh = $self->connect; - - my $query = <do($query); -} - -sub shrink_segment { - my $self = shift; - my $seg = shift; - - my $query; - - my $dbh = $self->connect; - for my $rec ('C3', 'C2', 'C1') { - next if not defined($seg->{$rec}); - $dbh->do($seg->{$rec}); - } -} - -sub shrink_segments_postgresql { - my $self = shift; - - my $dbh = $self->connect; - $dbh->{AutoCommit} = 1; - $dbh->do("VACUUM"); - $dbh->{AutoCommit} = 0; -} - -sub listener_startup { - my $self = shift; - - # ugly, but not much we really can do anyway; if it fails, it fails. - # Unpleasant, though. - my $lsnrctl = catfile($self->config->get("oracle_home"), 'bin', 'lsnrctl'); - system("$lsnrctl start &> /dev/null"); -} - -sub listener_shutdown { - my $self = shift; - - # ditto comment above - my $lsnrctl = catfile($self->config->get("oracle_home"), 'bin', 'lsnrctl'); - system("$lsnrctl stop &> /dev/null"); -} - -sub database_startup { - my $self = shift; - my $mode = shift; - - if ($mode) { - $mode = uc $mode; - } - else { - $mode = ''; - } - - $self->sqlplus_nolog("STARTUP $mode"); -} - -sub database_shutdown { - my $self = shift; - my $mode = shift; - - if ($mode) { - $mode = uc $mode; - } - else { - $mode = ''; - } - - $self->sqlplus_nolog("SHUTDOWN $mode"); -} - -sub get_optimizer_mode { - my $self = shift; - - my $dbh = $self->connect; - - my $sql = q{ - select value - from v$system_parameter - where name = 'optimizer_mode' - }; - - my @mode = $dbh->selectrow_array($sql, {}, ()); - - return $mode[0]; -} - -sub set_optimizer_mode { - my $self = shift; - my $mode = shift; - - my $dbh = $self->connect; - my @mode = $dbh->do("alter system set optimizer_mode = '" . $mode . "'"); -} - -sub sqlplus_nolog { - my $self = shift; - my @commands = @_; - - Dobby::Log->log("Connecting via sqlplus as sysdba..."); - - $ENV{ORACLE_SID} = $self->config->get("sid"); - $ENV{ORACLE_HOME} = $self->config->get("oracle_home"); - - my $sqlplus = catfile($self->config->get("oracle_home"), 'bin', 'sqlplus'); - my($chld_out, $chld_in); - my $pid = IPC::Open2::open2($chld_out, $chld_in, $sqlplus, '-S', '/nolog'); - my $rs = IO::Select->new($chld_out); - my $ws = IO::Select->new($chld_in); - my $es = IO::Select->new($chld_out, $chld_in); - while ($rs->handles and $ws->handles - and my ($rds, $wrs, $errs) = IO::Select->select($rs, $ws, $es)) { - if (defined $errs and @$errs) { - for my $e (@$errs) { - $es->remove($e); - $e->close; - } - } - elsif (defined $rds and @$rds) { - my $buffer = ''; - sysread $rds->[0], $buffer, 1024; - if (length($buffer) == 0) { - $rs->remove($rds->[0]); - } else { - Dobby::Log->log(" read: $buffer"); - } - } - elsif (defined $wrs and @$wrs) { - if (@commands) { - my $command = shift @commands; - Dobby::Log->log(" sent: $command"); - $wrs->[0]->print("CONNECT / AS SYSDBA\n"); - $wrs->[0]->print("$command\n"); - } else { - $wrs->[0]->print("EXIT\n"); - $ws->remove($wrs->[0]); - $wrs->[0]->close; - } - } - } - - Dobby::Log->log("Completed sqlplus conversation"); -} - -sub connect { - my $self = shift; - - return $self->{dbh} if $self->{dbh}; - $self->{dbh} = RHN::DBI->connect; - return $self->{dbh}; -} - -sub pg_instance_state { - my $self = shift; - if (defined $RHN::DB::dbh and $RHN::DB::dbh->ping()) { - return "OPEN"; - } - my ($dsn, $login, $password, $attr) = RHN::DBI::_get_dbi_connect_parameters(); - my $dbh = eval { RHN::DB->direct_connect($dsn, $login, $password, $attr) }; - return $dbh ? "OPEN" : "OFFLINE"; -} - -sub instance_state { - my $self = shift; - my $backend = PXT::Config->get('db_backend'); - return ($backend eq 'postgresql') ? $self->pg_instance_state : $self->ora_instance_state; -} - -sub ora_instance_state { - my $self = shift; - # ORA-01033 -- startup/shutdown in progress (mounted but not open) - # ORA-01089 -- immediate startup/shutdown in progress (shutdown in progress) - # ORA-01034 -- oracle not available - - my $dbh = eval { $self->sysdba_connect }; - $dbh->disconnect if $dbh; - delete $self->{sysdbh}; - my $err = RHN::DB->err; - - if (not $err) { - return "OPEN"; - } - - my %states = (1033 => "MOUNTED", - 1089 => "STOPPING", - 1034 => "OFFLINE"); - - croak "Unknown error code $err " . RHN::DB->errstr if not exists $states{$err}; - - return $states{$err}; -} - -sub sysdba_connect { - my $self = shift; - return $self->{sysdbh} if $self->{sysdbh}; - my $backend = PXT::Config->get('db_backend'); - return ($backend eq 'postgresql') ? $self->sysdba_connect_postgresql : $self->sysdba_connect_oracle; -} - -sub sysdba_connect_postgresql { - my $self = shift; - my ($dsn, $login, $password, $attr) = RHN::DBI::_get_dbi_connect_parameters(); - my $dbh = eval { RHN::DB->direct_connect($dsn, $login, $password, $attr) }; - $self->{sysdbh} = $dbh; - return $dbh; -} - -sub sysdba_connect_oracle { - my $self = shift; - - $ENV{ORACLE_SID} = $self->config->get("sid"); - $ENV{ORACLE_HOME} = $self->config->get("oracle_home"); - - my %params = (RaiseError => 1, - PrintError => 0, - AutoCommit => 0, - ora_session_mode => 2); # ora_session_mode: OCI_SYSDBA - - my $dbi_str = "dbi:Oracle:"; - - # this is a terrible workaround for a bug in DBI. When doing - # ora_session_mode commits with DBI 1.37 and DBD-Oracle 1.14, there - # is a place in the connect call that drh->errstr is undefined. DBI - # then concats this string with a general error string. Result is a - # bizarre spurious warning. To get around it, we muffle it with a - # locally defined __WARN__ "signal" handler. Truly terrible, but necessary. - - local $SIG{__WARN__} = sub { - my $str = shift; - if ($str =~ /Use of uninitialized value in concatenation/) { - # nop -- hide this error - } - else { - warn "X: $str"; - } - }; - - my $dbh = RHN::DB->direct_connect($dbi_str, - $self->config->get("sysdba_username"), - $self->config->get("sysdba_password"), - \%params); - - $self->{sysdbh} = $dbh; - return $dbh; -} - -sub password_reset { - my $self = shift; - my $user = PXT::Config->get("db_user"); - my $password = PXT::Config->get("db_password"); - my $backend = PXT::Config->get('db_backend'); - my $dsn = "dbi:Pg:dbname=".PXT::Config->get("db_name"); - my $dbh = ($backend eq 'postgresql') ? RHN::DB->direct_connect($dsn, "postgres") : $self->sysdba_connect; - my $query = ($backend eq 'postgresql') ? - qq{ALTER USER $user WITH ENCRYPTED PASSWORD '$password'}: - qq{ALTER USER $user IDENTIFIED BY "$password" ACCOUNT UNLOCK}; - if ($dbh->do($query)) { - return $user; - } - return 0; -} - -1; diff --git a/web/modules/dobby/Dobby/Files.pm b/web/modules/dobby/Dobby/Files.pm deleted file mode 100644 index a45e6f74b271..000000000000 --- a/web/modules/dobby/Dobby/Files.pm +++ /dev/null @@ -1,145 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::Files; -use Digest::MD5; -use Compress::Zlib; -use File::Basename qw/basename dirname/; -use File::Spec; -use File::Path; - -# returns md5 checksum of file given by filename -sub md5_checksum { - my $filename = shift; - - open my $file, '<', $filename or die "open $filename: $!\n"; - my $ctx = new Digest::MD5; - $ctx->addfile($file); - close $file; - - return $ctx->hexdigest; -} - -# given source and dst, gzip a file into dst, returning the checksum -# of the original file -sub gzip_copy { - my $class = shift; - my $src = shift; - my $dst = shift; - - local * IN; - open IN, '<', $src or die "open $src: $!\n"; - my $gz = gzopen("$dst", "wb") or die "gzopen: $!\n"; - - local $/ = \4096; - while () { - $gz->gzwrite($_) or die "gzwrite: $!\n"; - } - - $gz->gzclose; - close IN; - - return md5_checksum($dst); -} - -# gunzip's a file from src to dst. if dst is undef, then it the -# target is not written to (though digest is returned, so this checks -# integrity of the archive) - -sub gunzip_copy { - my ($class, $src, $dst, $uid, $gid) = @_; - if (defined($uid) or defined($gid)) { - # if not defined set it to -1 i.e. no change - $uid = -1 if not defined $uid; - $gid = -1 if not defined $gid; - } - - my $write; - local * OUT; - if ($dst) { - my $dst_directory = dirname($dst); - if (my @dirs = File::Path::mkpath($dst_directory, 0, 0700)) { - chown $uid, $gid, @dirs; - } - open OUT, '>', $dst or die "open $dst: $!\n"; - $write = 1 - } - else { - $write = 0; - } - - my $gz = gzopen("$src", "rb") or die "gzopen $src: $!\n"; - - local $/ = \4096; - while (1) { - my $block; - my $count = $gz->gzread($block); - # count is zero on EOF - last if $count == 0; - die "read error: $!\n" if $count < 0; - - if ($write) { - print OUT $block - or die "write to $dst: $!\n"; - } - } - - $gz->gzclose; - close OUT if $write; - if (defined($dst)) { - # if not defined set it to -1 i.e. no change - $uid = -1 if not defined $uid; - $gid = -1 if not defined $gid; - chown $uid, $gid, $dst; - chmod 0640, $dst; - } - - return md5_checksum($src); -} - -sub backup_file { - my ($class, $rel_dir, $file, $backup_dir) = @_; - - if (-d $file) { #empty directory - my $dir_entry = new Dobby::BackupLog::DirEntry; - $dir_entry->from($file); - print " Empty directory $file\n"; - return $dir_entry; - } else { - my $file_entry = new Dobby::BackupLog::FileEntry; - my $real_dest_dir = File::Spec->catdir($backup_dir, $rel_dir); - eval { File::Path::mkpath($real_dest_dir) } or (-d $real_dest_dir) or die ("Error: could not create directory $real_dest_dir\n"); - my $dest = sprintf("%s/%s.gz", $real_dest_dir, basename($file)); - $dest =~ s(//+)(/)g; - my $then = time; - - $file_entry->start(time); - - print " $file -> $dest ... "; - my $hexdigest = Dobby::Files->gzip_copy($file, $dest); - print "done.\n"; - - $file_entry->original_size(-s $file); - $file_entry->compressed_size(-s $dest); - $file_entry->from($file); - $file_entry->to(File::Spec->abs2rel($dest, $backup_dir)); - $file_entry->finish(time); - $file_entry->digest($hexdigest); - return $file_entry; - } -} - -1; diff --git a/web/modules/dobby/Dobby/Log.pm b/web/modules/dobby/Dobby/Log.pm deleted file mode 100644 index 5f18c5daeed8..000000000000 --- a/web/modules/dobby/Dobby/Log.pm +++ /dev/null @@ -1,47 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; -package Dobby::Log; -use Fcntl; -use POSIX qw/strftime/; - -sub log { - my $class = shift; - - my $fh = $class->fetch_logger; - - my $str = (@_ > 1 ? sprintf @_ : $_[0]); - $str .= "\n" unless $str =~ /\n$/; - - $str = strftime("[%a %b %d %H:%M:%S %Y]", localtime time) . " $str"; - print $fh $str; -} - -my $global_fh; -my $global_logfile = "/var/log/rhn/rhn_database.log"; - -sub fetch_logger { - my $class = shift; - - if (not defined $global_fh) { - sysopen $global_fh, "$global_logfile", O_WRONLY | O_APPEND | O_CREAT - or die "open $global_logfile: $!"; - } - - return $global_fh; -} - -1; diff --git a/web/modules/dobby/Dobby/Reporting.pm b/web/modules/dobby/Dobby/Reporting.pm deleted file mode 100644 index b4def0e75589..000000000000 --- a/web/modules/dobby/Dobby/Reporting.pm +++ /dev/null @@ -1,155 +0,0 @@ -# -# Copyright (c) 2008--2015 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -use strict; - -package Dobby::Reporting; -use Dobby::DB; - -sub tablespace_overview_oracle { - my $class = shift; - my $dobby = shift; - - my $dbh = $dobby->sysdba_connect; - - my $query = <prepare($query); - $sth->execute; - return $sth->fullfetch_hashref; -} - -sub tablespace_overview_postgresql { - my $class = shift; - my $dobby = shift; - my $schema = shift; - - my $dbh = $dobby->sysdba_connect; - - my $query = <prepare($query); - $sth->execute($schema); - return $sth->fullfetch_hashref; -} - -sub table_size_overview_postgresql { - my $class = shift; - my $dobby = shift; - - my $dbh = $dobby->sysdba_connect; - - my $query = <prepare($query); - $sth->execute; - return $sth->fullfetch_hashref; -} - -sub table_size_overview_oracle { - my $class = shift; - my $dobby = shift; - - my $dbh = $dobby->sysdba_connect; - - my $uppercaseuser=uc($dobby->normal_user); - - my $query = <prepare($query); - $sth->execute; - return $sth->fullfetch_hashref; -} - -sub segadv_recomendations { - my $class = shift; - my $dobby = shift; - - my $dbh = $dobby->connect; - - my $query = <prepare($query); - $sth->execute; - return @{$sth->fetchall_arrayref({ })}; -} - -sub active_sessions_postgresql { - my $class = shift; - my $dbh = shift; - my $schema = shift; - - my $query = "SELECT COUNT(*) FROM pg_stat_activity WHERE datname = ?"; - - my $sth = $dbh->prepare($query); - $sth->execute($schema); - return $sth->fetch()->[0]; -} - -1; diff --git a/web/modules/dobby/Makefile b/web/modules/dobby/Makefile deleted file mode 100644 index 137f9ded547e..000000000000 --- a/web/modules/dobby/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# dummy Makefile for perl module -# - -TOP = ../.. -export TOP - -include $(TOP)/Makefile.defs diff --git a/web/modules/dobby/Makefile.PL b/web/modules/dobby/Makefile.PL deleted file mode 100644 index 697e68d84653..000000000000 --- a/web/modules/dobby/Makefile.PL +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/perl -# perl makefile for the dobby module -# - -use ExtUtils::MakeMaker; -# See lib/ExtUtils/MakeMaker.pm for details of how to influence -# the contents of the Makefile that is written. - -my $file = qx|ls $ENV{'TOP'}/*.spec|; -chomp $file; -my $version = qx|grep '^Version: ' $file|; -chomp $version; -$version = (split /\s*:\s*/, $version)[-1]; - -die "No version or name from $file" unless $version; - -WriteMakefile('NAME' => "Dobby", - 'VERSION' => $version, - 'LIBS' => [''], # e.g., '-lm' - 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' - 'INC' => '', # e.g., '-I/usr/include/other' - 'MAKEFILE' => "Makefile.perl", # the name of the output Makefile file - 'EXE_FILES' => [ "scripts/db-control" ], -); - -package MY; -sub tools_other { - my $self = shift; - my $ret = $self->SUPER::tools_other(@_); - $ret =~ s/^(FIXIN\b.+)$/## $1\nFIXIN = \$(PERLRUN) -e 1/m; - return $ret; -} diff --git a/web/modules/dobby/scripts/check-database-space-usage.sh b/web/modules/dobby/scripts/check-database-space-usage.sh deleted file mode 100755 index c26ffa9c7e30..000000000000 --- a/web/modules/dobby/scripts/check-database-space-usage.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -# Copyright (c) 2008--2018 Red Hat, Inc. -# -# This software is licensed to you under the GNU General Public License, -# version 2 (GPLv2). There is NO WARRANTY for this software, express or -# implied, including the implied warranties of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 -# along with this software; if not, see -# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. -# -# Red Hat trademarks are not licensed under GPLv2. No permission is -# granted to use or replicate Red Hat trademarks that are incorporated -# in this software or its documentation. -# - -PATH=/usr/bin:/bin -export PATH - -mailitout() { - local reportusage=$1 - - #get Satellite email address - MAILADDRESS="root@localhost" - if [ -e /usr/bin/spacewalk-cfg-get ]; then - MAILADDRESS=$(spacewalk-cfg-get traceback_mail) - fi - - SUBJECT="Warning - PostgreSQL database mount point is running out of space" - BODY="This is a notice to let you know that you have gone over 90% usage of -the mount point where the PostgreSQL database resides. We recommend to be -proactive and increase the storage before getting to 100% usage." - - echo -e "$BODY\n\n$reportusage" | mail -s "$SUBJECT" $MAILADDRESS - exit 0 -} - -DATADIR="/var/lib/pgsql/data/" -if rpm -q postgresql92-postgresql-server > /dev/null; then - DATADIR="/opt/rh/postgresql92/root/var/lib/pgsql/data/" -fi - -if rpm -q rh-postgresql95-postgresql > /dev/null; then - DATADIR="/var/opt/rh/rh-postgresql95/lib/pgsql/data" -fi - -if [ -f /usr/share/rhn/config-defaults/rhn_pgversion.conf ]; then - if [ ! -z "$(grep pg_version /usr/share/rhn/config-defaults/rhn_pgversion.conf | sed 's/.*=\s*//')" ]; then - DATADIR="$(grep pg_home /usr/share/rhn/config-defaults/rhn_pgversion.conf | sed 's/.*=\s*//')" - fi -fi - -# check if DATADIR is a directory -if [ ! -d $DATADIR ]; then - exit 1 -fi - -REPORTUSAGE=$(df -hP $DATADIR) -NUMBERS=$(echo "$REPORTUSAGE" | awk '{if (FNR > 1) {sub("%",""); print $5}}') - -for num in $NUMBERS - do - # if number is over 90% then send warning email - if [ $num -gt 90 ] - then mailitout "$REPORTUSAGE" - fi -done -exit 0 diff --git a/web/modules/dobby/scripts/db-control b/web/modules/dobby/scripts/db-control deleted file mode 100755 index 3979ed9ca1c0..000000000000 --- a/web/modules/dobby/scripts/db-control +++ /dev/null @@ -1,171 +0,0 @@ -#!/usr/bin/perl -w -use strict; - -use File::Basename; - -use PXT::Config; -use Dobby::CLI; -use Dobby::CLI::MiscCommands; -use Dobby::CLI::MaintCommands; -use Dobby::CLI::BackupCommands; -use Dobby::Log; - -$PXT::Config::default_config = new PXT::Config('dobby'); - -my $exec_name = basename $0; -my $cli = new Dobby::CLI $exec_name; - -my $backend = PXT::Config->get('db_backend'); -my $cfg = new PXT::Config("dobby"); -my $intended_username = $cfg->get("${backend}_user"); -my ($username, undef, $uid, $gid) = getpwnam($intended_username); - -if (not defined $uid or not defined $gid or $uid != $> or $gid != $)) { - if ($backend eq 'postgresql') { - # postgresql backend can be run as root or postgres user - if ( $> != 0 or $) != 0) { - $cli->fatal("Error: please run this command as the root ('su -')."); - } - } else { # oracle backend can be run only as oracle user - no warnings 'syntax'; - exec '/sbin/runuser', '-', $intended_username, '-c', join ' ', map "'$_'", $0, @ARGV; - $cli->fatal("Error: runuser $intended_username failed"); - } -} - -Dobby::CLI::MiscCommands->register_dobby_commands($cli); -Dobby::CLI::MaintCommands->register_dobby_commands($cli); -Dobby::CLI::BackupCommands->register_dobby_commands($cli); - -my ($mode, @params) = @ARGV; - -# default to the 'help' command -if (not $mode) { - $mode = "help"; - @params = (); -} - -# force autoflush on stdout write -$|++; - -Dobby::Log->log("Invocation: db-control $mode @params"); -my $status = $cli->invoke_command($mode, @params); -Dobby::Log->log("Completed: db-control $mode @params"); - -exit $status || 0; - -=head1 NAME - -db-control - utility for managing the SUSE Manager database - -=head1 SYNOPSIS - -B -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] -[B] - -=head1 OPTIONS - -=over 5 - -=item B - -Backs up the database. Backup files will be stored in directory DIRNAME. Note that this is a cold backup; the database must be stopped before running this command. It's advisable to create a new backup directory for each new backup. - -Backups take several minutes; the first backup will be a good indicator of how long subsequent backups will take. - -=item B - -Examines the contents of a backup directory. Quicker than B, this command returns the timestamp of backup creation and reports on its contents, noting any missing files. - -=item B - -Increases the tablespace size for TABLESPACE by adding an additional datafile. (Oracle only) - -=item B - -Gather statistics on database objects. On Oracle PCT is the percentage of rows to estimate (the default is 15 per cent). On PostgreSQL PCT does not have sense. - -=item B - -Show database optimizer mode (Oracle only). - -=item B - -Gives a list of db-control options. - -=item B - -Perform online backup of database. This works only with PostgreSQL backend and FILE must be in directory writeable by postgres user. While this backup method is slower compared to "backup" (aprox. 4 times). You do not need to shut down neither Spacewalk services nor DB service. - -=item B - -Restores the database from backup file FILE, which was made by command "pg-online-backup". This command will shut down all Spacewalk services and leave only database running. Then all objects from DB are removed and backup is restored. You have to start up Spacewalk services manualy. - -=item B - -Reports on current usage of database space. - -=item B - -Reports tables with stale or empty statistics. On Oracle DAYS are ignored. On PostgreSQL shows tables, which has not been ANALYZED (gather-stats do that) for DAYS days. Default is one day. - -=item B - -Resets database password according to value in /etc/rhn/rhn.conf. - -=item B - -Restores the database from backup kept in DIRNAME. Database must be stopped for this command to run successfully. - -Before restoring, the files in DIRNAME are verified. Once all files are verified successfully, the restore runs. Once the restore is completed, the database may be started and run normally. - -=item B - -Set database optimizer mode to ALL_ROWS (Oracle only). - -=item B - -Determines and shrinks database segments with signifcant amount of free space. - -=item B - -Starts the database instance. - -=item B - -Shows the current status of the database, either "running" or "offline". - -=item B - -Stops the SUSE Manager database instance. This is required to perform B or B actions. - -=item B - -Show space report for each table. On PostgreSQL the meaning of columns is as follows: "Planner Size" - size which planner uses for determining execution plan. It may differ from real size. "Real Size" - real size of data file on disk. "Real Size+Toasts+Idx" - real size of data file on disk, including TOAST (The Oversized-Attribute Storage Technique) and indexes. - -=item B - -Verifies the contents of the backup kept in DIRNAME. This command checks the md5sums of each of the files kept in the backup. - -=back - -=head1 SEE ALSO - -B(8), B(8), B(8), B(8), B(8), B(8) - diff --git a/web/modules/dobby/test.pl b/web/modules/dobby/test.pl deleted file mode 100644 index fa3ae54986f7..000000000000 --- a/web/modules/dobby/test.pl +++ /dev/null @@ -1,20 +0,0 @@ -# Before `make install' is performed this script should be runnable with -# `make test'. After `make install' it should work as `perl test.pl' - -######################### We start with some black magic to print on failure. - -# Change 1..1 below to 1..last_test_to_print . -# (It may become useful if the test is moved to ./t subdirectory.) - -BEGIN { $| = 1; print "1..1\n"; } -END {print "not ok 1\n" unless $loaded;} -use Dobby; -$loaded = 1; -print "ok 1\n"; - -######################### End of black magic. - -# Insert your test code below (better if it prints "ok 13" -# (correspondingly "not ok 13") depending on the success of chunk 13 -# of the test code): - diff --git a/web/spacewalk-web.changes.rmateus.uyuni_remove_dobby_perl b/web/spacewalk-web.changes.rmateus.uyuni_remove_dobby_perl new file mode 100644 index 000000000000..96cf64de8fe9 --- /dev/null +++ b/web/spacewalk-web.changes.rmateus.uyuni_remove_dobby_perl @@ -0,0 +1 @@ +- remove unused module dobby diff --git a/web/spacewalk-web.spec b/web/spacewalk-web.spec index 1e1211d205f2..6fcbb49aecc1 100644 --- a/web/spacewalk-web.spec +++ b/web/spacewalk-web.spec @@ -153,21 +153,6 @@ Provides: spacewalk(spacewalk-base-minimal-config) = %{version}-%{release} %description -n spacewalk-base-minimal-config Configuration file for spacewalk-base-minimal package. -%package -n spacewalk-dobby -Summary: Perl modules and scripts to administer a PostgreSQL database -License: GPL-2.0-only -# FIXME: use correct group or remove it, see "https://en.opensuse.org/openSUSE:Package_group_guidelines" -Group: Applications/Internet -Requires: %{sbinpath}/runuser -Requires: perl-Filesys-Df -Conflicts: spacewalk-oracle -Obsoletes: rhn-dobby < 5.3.0 -Provides: rhn-dobby = 5.3.0 - -%description -n spacewalk-dobby -Dobby is collection of Perl modules and scripts to administer a PostgreSQL -database. - %prep %setup -q pushd html/src @@ -199,8 +184,6 @@ mkdir -p %{buildroot}%{_sysconfdir}/httpd/conf mkdir -p %{buildroot}%{_sysconfdir}/cron.daily install -m 644 conf/rhn_web.conf %{buildroot}%{_datadir}/rhn/config-defaults -install -m 644 conf/rhn_dobby.conf %{buildroot}%{_datadir}/rhn/config-defaults -install -m 755 modules/dobby/scripts/check-database-space-usage.sh %{buildroot}%{_sysconfdir}/cron.daily/check-database-space-usage.sh if grep -F 'product_name' %{_datadir}/rhn/config-defaults/rhn.conf | grep 'SUSE Manager' >/dev/null; then SUMA_REL=$(echo %{version} | awk -F. '{print $1"."$2}') @@ -251,16 +234,6 @@ sed -i -e 's/^web.theme_default =.*$/web.theme_default = susemanager-light/' %{b %dir %{_datadir}/rhn %attr(644,root,%{apache_group}) %{_datadir}/rhn/config-defaults/rhn_web.conf -%files -n spacewalk-dobby -%defattr(644,root,root,755) -%attr(755,root,root) %{_bindir}/db-control -%{_mandir}/man1/db-control.1%{?ext_man} -%{perl_vendorlib}/Dobby.pm -%attr(644,root,root) %{_datadir}/rhn/config-defaults/rhn_dobby.conf -%attr(0755,root,root) %{_sysconfdir}/cron.daily/check-database-space-usage.sh -%{perl_vendorlib}/Dobby/ -%dir %{_datadir}/rhn - %files -n spacewalk-html -f spacewalk-web.lang %defattr(644,root,root,755) %dir %{shared_path}