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
49cf54f2
Commit
49cf54f2
authored
13 years ago
by
Andy Yates
Browse files
Options
Downloads
Patches
Plain Diff
Switching to using patterns
parent
bb3c174a
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
+40
-28
40 additions, 28 deletions
misc-scripts/db/cleanup_tmp_tables.pl
with
40 additions
and
28 deletions
misc-scripts/db/cleanup_tmp_tables.pl
+
40
−
28
View file @
49cf54f2
...
...
@@ -10,11 +10,13 @@ cleanup_tmp_tables.pl - delete temporary and backup tables from a database
./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 '%mydbs%' --dry_run
./cleanup_tmp_tables.pl --nolog --host localhost --port 3306 --user user --dbname DB --interactive 0
Required arguments:
--dbname, db_name=NAME database name NAME
--dbname, db_name=NAME database name NAME
(can be a pattern)
--host, --dbhost, --db_host=HOST database host HOST
--port, --dbport, --db_port=PORT database port PORT
--user, --dbuser, --db_user=USER database username USER
...
...
@@ -59,9 +61,7 @@ table. This means any table which contains
=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.
You can run this over multiple DBs but caution is advised
=head1 LICENCE
...
...
@@ -120,8 +120,18 @@ $support->init_log;
$support
->
check_required_params
;
# connect to database and get adaptors
my
$dba
=
$support
->
get_database
('
ensembl
');
my
@databases
;
# connect to database
my
$dbh
=
$support
->
get_dbconnection
('');
if
(
$support
->
param
('
dbname
')
=~
/%/
)
{
my
$ref
=
$dbh
->
selectall_arrayref
('
show databases like ?
',
{},
$support
->
param
('
dbname
'));
push
(
@databases
,
map
{
$_
->
[
0
]}
@
{
$ref
})
}
else
{
push
(
@databases
,
$support
->
param
('
dbname
'));
}
# find all temporary and backup tables
my
@tables
;
...
...
@@ -133,32 +143,34 @@ 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
(
@tables
)
{
$support
->
log
("
$table
\n
",
1
);
foreach
my
$db
(
@databases
)
{
$support
->
log
('
Switching to
'
.
$db
);
$dbh
->
do
('
use
'
.
$db
);
foreach
my
$pattern
(
@patterns
)
{
my
$ref
=
$dbh
->
selectall_arrayref
('
show tables like ?
',
{},
$pattern
);
push
(
@tables
,
map
{
$_
->
[
0
]}
@
{
$ref
});
}
}
else
{
# delete tables
foreach
my
$table
(
@tables
)
{
if
(
$support
->
user_proceed
("
Drop table
$table
?
"))
{
$support
->
log
("
Dropping table
$table
...
\n
");
$dba
->
dbc
()
->
do
("
DROP TABLE
$table
");
$support
->
log
("
Done.
\n
");
@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
(
@tables
)
{
$support
->
log
("
$table
\n
",
1
);
}
}
else
{
# delete tables
foreach
my
$table
(
@tables
)
{
if
(
$support
->
user_proceed
("
Drop table
$table
?
"))
{
$support
->
log
("
Dropping table
$table
...
\n
");
$dbh
->
do
("
DROP TABLE
$table
");
$support
->
log
("
Done.
\n
");
}
}
}
}
# finish logfile
$support
->
finish_log
;
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