Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
13c281f6
Commit
13c281f6
authored
13 years ago
by
Andy Yates
Browse files
Options
Downloads
Patches
Plain Diff
Adding support for mart temporary tables and making the documentation clearer
parent
54299532
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc-scripts/db/cleanup_tmp_tables.pl
+44
-14
44 additions, 14 deletions
misc-scripts/db/cleanup_tmp_tables.pl
with
44 additions
and
14 deletions
misc-scripts/db/cleanup_tmp_tables.pl
+
44
−
14
View file @
13c281f6
#!/usr/
local/ensembl/
bin/perl
#!/usr/bin/
env
perl
=head1 NAME
...
...
@@ -6,7 +6,11 @@ cleanup_tmp_tables.pl - delete temporary and backup tables from a database
=head1 SYNOPSIS
cleanup_tmp_tables.pl [arguments]
./cleanup_tmp_tables.pl [arguments]
./cleanup_tmp_tables.pl --nolog --host localhost --port 3306 --user user --dbname DB --dry_run
./cleanup_tmp_tables.pl --nolog --host localhost --port 3306 --user user --dbname DB --interactive 0
Required arguments:
...
...
@@ -18,6 +22,10 @@ Required arguments:
Optional arguments:
--mart Indicates we wish to search for mart
temporary tables which are normally
prefixed with MTMP_
--conffile, --conf=FILE read parameters from FILE
(default: conf/Conversion.ini)
...
...
@@ -32,6 +40,26 @@ Optional arguments:
=head1 DESCRIPTION
A script which looks for any table which we believe could be a temporary
table. This means any table which contains
=over 8
=item tmp
=item temp
=item bak
=item backup
=item MTMP_ (only used when --mart is specified)
=back
The code is designed to be run over a single database to avoid the
unintentional and accidental dropping of temporary tables which are still
in use.
=head1 LICENCE
...
...
@@ -72,8 +100,9 @@ my $support = new Bio::EnsEMBL::Utils::ConversionSupport($SERVERROOT);
# parse options
$support
->
parse_common_options
(
@
_
);
$support
->
parse_extra_options
(
qw/mart!/
);
$support
->
allowed_params
(
$support
->
get_common_params
,
$support
->
get_common_params
,
'
mart
'
);
if
(
$support
->
param
('
help
')
or
$support
->
error
)
{
...
...
@@ -91,33 +120,34 @@ $support->check_required_params;
# connect to database and get adaptors
my
$dba
=
$support
->
get_database
('
ensembl
');
my
$dbh
=
$dba
->
dbc
->
db_handle
;
# find all temporary and backup tables
my
@tables
;
foreach
my
$
pattern
(
qw
(
tmp temp bak backup
)
)
{
my
$sql
=
qq(SHOW TABLES LIKE '\%$pattern\%
')
;
my
$sth
=
$dbh
->
prepare
(
$sql
);
$sth
->
execute
;
while
(
my
(
$table
)
=
$sth
->
fetchrow_array
)
{
push
@tables
,
$table
;
}
my
@
pattern
s
=
map
{
'
%
'
.
$_
.
'
%
'
}
qw
/
tmp temp bak backup
/
;
push
(
@patterns
,
'
MTMP\_%
')
if
$support
->
param
('
mart
');
foreach
my
$pattern
(
@patterns
)
{
my
$results
=
$dba
->
dbc
()
->
sql_helper
()
->
execute_simple
(
-
SQL
=>
'
SHOW TABLES LIKE ?
',
-
PARAMS
=>
[
$pattern
])
;
push
(
@tables
,
@
{
$results
});
}
@tables
=
sort
@tables
;
if
(
$support
->
param
('
dry_run
'))
{
# for a dry run, only show which databases would be deleted
$support
->
log
("
Temporary and backup tables found:
\n
");
foreach
my
$table
(
sort
@tables
)
{
foreach
my
$table
(
@tables
)
{
$support
->
log
("
$table
\n
",
1
);
}
}
else
{
# delete tables
foreach
my
$table
(
sort
@tables
)
{
foreach
my
$table
(
@tables
)
{
if
(
$support
->
user_proceed
("
Drop table
$table
?
"))
{
$support
->
log
("
Dropping table
$table
...
\n
");
$db
h
->
do
("
DROP TABLE
$table
");
$db
a
->
dbc
()
->
do
("
DROP TABLE
$table
");
$support
->
log
("
Done.
\n
");
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment