[Rt-commit] r2283 - misc_support_scripts

jesse at bestpractical.com jesse at bestpractical.com
Sat Mar 5 19:01:08 EST 2005


Author: jesse
Date: Sat Mar  5 19:01:07 2005
New Revision: 2283

Added:
   misc_support_scripts/delete_orphans
   misc_support_scripts/delete_sessions
   misc_support_scripts/nuke-schema.pl   (contents, props changed)
   misc_support_scripts/rt-filler
   misc_support_scripts/signrt   (contents, props changed)
Log:
Collecting RT support scripts of various sorts.



Added: misc_support_scripts/delete_orphans
==============================================================================
--- (empty file)
+++ misc_support_scripts/delete_orphans	Sat Mar  5 19:01:07 2005
@@ -0,0 +1,46 @@
+
+# Doesn't do anything yet
+
+use warnings;
+use strict;
+use RT;
+RT::LoadConfig();
+RT::Init();
+use RT::Users;
+use RT::Groups;
+use RT::Transactions;
+
+
+my $users = RT::Users->new($RT::SystemUser);
+$users->OrderBy (FIELD => 'id');
+my $unpriv = RT::Group->new( $RT::SystemUser);
+        $unpriv->LoadSystemInternalGroup('Unprivileged');
+            unless ( $unpriv->Id ) {
+                    die "Couldn't find an unprivileged users group";
+                        }
+                            $users->MemberOfGroup( $unpriv->PrincipalId );
+
+
+while (my $u = $users->Next) {
+    print $u->id.": ".$u->Name ."\n";
+
+    my $groups = RT::Groups->new($RT::SystemUser);
+    $groups->WithMember(PrincipalId => $u->id, Recursively => 1) ;
+    $groups->Limit(FIELD => 'Domain', OPERATOR => '!=', VALUE =>'SystemInternal', ENTRYAGGREGATOR => 'AND');
+    $groups->Limit(FIELD => 'Domain', OPERATOR => '!=', VALUE =>'ACLEquivalence' , ENTRYAGGREGATOR => 'AND');
+
+
+    my $txns = RT::Transactions->new($RT::SystemUser);
+    $txns->Limit(FIELD => 'Creator', VALUE => $u->id);
+    if ($txns->Count) {
+        print "\t...skipped (They still have  ".$txns->Count." transactions in the system)\n";
+        next;
+    }
+    if ($groups->Count)  {
+        print "\t...skipped (They're in ".$groups->Count." groups)\n";
+        print "\t".join(",", map { $_->id } @{$groups->ItemsArrayRef}) ."\n";
+        next;
+    }
+
+    print "\t READY TO DELETE\n";
+}

Added: misc_support_scripts/delete_sessions
==============================================================================
--- (empty file)
+++ misc_support_scripts/delete_sessions	Sat Mar  5 19:01:07 2005
@@ -0,0 +1,6 @@
+#!/usr/bin/perl
+use lib qw(/opt/rt/rt3.fsck.com/lib/);
+use RT;
+RT::LoadConfig();
+RT::Init();
+print $RT::Handle->SimpleQuery("delete from sessions where LastUpdated < (now() - interval 24 hour)")->fetchrow;

Added: misc_support_scripts/nuke-schema.pl
==============================================================================
--- (empty file)
+++ misc_support_scripts/nuke-schema.pl	Sat Mar  5 19:01:07 2005
@@ -0,0 +1,88 @@
+#!/mv/local/bin/perl
+
+use Scriptalicious
+    -progname => "nuke-schema";
+
+=head1 NAME
+
+nuke-schema - Obliterate an Oracle schema
+
+=head1 SYNOPSIS
+
+ nuke-schema user/password
+
+=head1 DESCRIPTION
+
+This script empties the specified schema, by dropping its tables,
+views, synonyms and sequences.  Use with reckless abandon.
+
+There is no way to delete another user's schema.
+
+Note that the script doesn't actually delete anything unless you run
+with the -y switch.
+
+=head1 COMMAND LINE OPTIONS
+
+=over
+
+=item B<-y, --yes>
+
+Don't just pretend - actually drop the schema.
+
+=item B<-h, --help>
+
+This help page
+
+=item B<-v, --verbose>
+
+Specify verbose operation
+
+=back
+
+=cut
+
+use strict;
+use DBI;
+
+my $dont_pretend;
+getopt("yes|y" => \$dont_pretend);
+
+my $cred = shift or abort "no login credentials given";
+
+my ($user, $password) = ($cred =~ m{^([^/]+)(?:/(.*))?$});
+$password or moan "connecting without a password";
+
+whisper "connecting to the $user schema";
+my $dbh = DBI->connect("dbi:Oracle:", $user, $password);
+
+for my $entity ( qw(table view synonym sequence) ) {
+
+    my $sth = $dbh->prepare (<<"SQL") or barf $dbh->errstr;
+SELECT
+    ${entity}_name
+FROM
+    user_${entity}s
+SQL
+    $sth->execute() or barf $dbh->errstr;
+
+    my @entity;
+    while ( my $row = $sth->fetchrow_arrayref ) {
+	push @entity, $row->[0]
+	    unless $row->[0] =~ m/BIN\$/;
+    }
+
+    say "dropping ". at entity." ${entity}s";
+    for my $item ( @entity ) {
+	$item =~ s{"}{""}g;
+	mutter "dropping $entity $item";
+	$dbh->do("drop $entity \"$item\"")
+	    if $dont_pretend;
+    }
+}
+
+$dbh->do("purge recyclebin")
+    if $dont_pretend;
+$dbh->disconnect();
+
+say "re-run with --yes option to actually clear the schema."
+    unless $dont_pretend;

Added: misc_support_scripts/rt-filler
==============================================================================
--- (empty file)
+++ misc_support_scripts/rt-filler	Sat Mar  5 19:01:07 2005
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use lib qw(/opt/rt3/lib);
+use Test::More qw/no_plan/;
+use RT;
+
+RT::LoadConfig;
+RT::Init;
+my $i;
+if (1) {
+for ($i=0;$i<50;$i++) {
+    my $q = RT::Queue->new($RT::SystemUser);
+    my ($id,$val) = $q->Create(Name => 'test-'.$i);
+    ok($id,$val);
+}
+for ($i=0;$i<1000;$i++) {
+    my $q = RT::User->new($RT::SystemUser);
+    my ($id,$val) = $q->Create(Name => 'test-'.$i, Privileged=>1);
+    ok($id,$val);
+}
+
+}
+
+for ($i=0; $i < 500000; $i++) {
+    my $t = RT::Ticket->new($RT::SystemUser);
+    my ($id,$txn,$msg) = $t->Create(Queue => int(rand(50)),
+               Subject => 'Test ticket #'.$i,
+               Requestor => 'example-'.int(rand($i)).'@example.com',
+               Owner => int(rand(1000)),
+               Content => ' blah  '.$i);
+
+    ok($id, $msg . " - $id");
+}
+
+

Added: misc_support_scripts/signrt
==============================================================================
--- (empty file)
+++ misc_support_scripts/signrt	Sat Mar  5 19:01:07 2005
@@ -0,0 +1,11 @@
+#!/usr/bin/perl -w
+
+use strict;
+my $rev = shift;
+$rev or die 'no file';
+
+`scp fsck.com:/opt/web/hosted/download.bestpractical.com/html/pub/rt/devel/$rev.tar.gz .`;
+die "File not found" unless (-f "$rev.tar.gz");
+`gpg --detach-sign $rev.tar.gz`;
+`scp $rev.tar.gz.sig fsck.com:/opt/web/hosted/download.bestpractical.com/html/pub/rt/devel/`;
+`md5sum $rev.*`;


More information about the Rt-commit mailing list