Tim Landscheidt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/104397
Change subject: Unreviewed changes to rmtool
......................................................................
Unreviewed changes to rmtool
Change-Id: Id28309442df5a149031962ea9e6953e8280a41b6
---
M misctools/rmtool
1 file changed, 56 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/labs/toollabs
refs/changes/97/104397/1
diff --git a/misctools/rmtool b/misctools/rmtool
index 06a7696..e6849a1 100755
--- a/misctools/rmtool
+++ b/misctools/rmtool
@@ -10,8 +10,24 @@
exit 1
fi
+echo "Don't forget to remove the entry in ldap first!! Once the record is
removed, continue"
+read p
+
tool=$1
+toolpath=/data/project/$tool
dbuser=`echo $1 | sed 's/-//'`
+original_dbuser=$dbuser
+dbuser2=null
+if [ -f "$toolpath/replica.my.cnf" ];then
+ dbuser2="$(sed -n -e "/user='\(.*\)'/{;s//\1/;p;}"
$toolpath/replica.my.cnf)"
+fi
+using_replica_only=0
+
+if [ ! -f "$toolpath/.my.cnf" ] && [ -f "$toolpath/replica.my.cnf" ];then
+ echo "Warning: user replica user only!"
+ using_replica_only=1
+ dbuser=$dbuser2
+fi
# get a number of users of this name in mysql
uc=`echo "select user from user;" | mysql mysql | grep -cE ^$dbuser'$'`
@@ -19,16 +35,48 @@
echo "There is $uc user accounts of name $dbuser in database"
if [ "$uc" -gt 0 ];then
+ echo I will now remove the db access, this can\'t be reverted, hit
enter to continue
+ read p
echo "Removing db access of $tool"
echo "drop user $dbuser;" | mysql mysql
fi
+if [ -f /var/spool/cron/crontabs/local-$tool ];then
+ echo "Attempting to clear the cron"
+ rm /var/spool/cron/crontabs/local-$tool
+fi
+
# get the number of databases for this user
-db=`echo "show databases;" | mysql mysql | grep -cE ^$dbuser'$'`
+db=`echo "show databases;" | mysql mysql | grep -cE ^$tool'$'`
+ db2=`echo "show databases;" | mysql mysql | grep -cE ^"$dbuser"__`
echo "There is $db databases of name $tool in database"
+echo "There is $db2 databases prefixed with $dbuser in database"
-if [ "$db" -gt 0 ];then
+if [ $db2 -gt 0 ];then
+ # backup all databases
+ list=`echo "show databases;" | mysql mysql | grep -E ^"$dbuser"__`
+ for database in `echo $list`
+ do
+ echo "Backing up database $database"
+ if [ -f "$toolpath/$database"_backup.sql ];then
+ echo "Error, there is already a backup file for this
db, process with manual backup and hit enter"
+ read p
+ else
+ mysqldump "$database" > "$toolpath/$database"_backup.sql
+ echo "Removing the database $database"
+ echo "drop database $database;" | mysql mysql
+ fi
+ done
+fi
+
+
+if [ $db -gt 1 ];then
+ echo "Warning there are more than 1 databases for this user, please
proceed with manual backup and hit enter to continue"
+ read p
+else
+
+ if [ "$db" -gt 0 ];then
echo "Creating a backup of database $tool"
if [ -f "/data/project/$tool/database_backup.sql" ];then
echo "Error there is already a backup file"
@@ -41,6 +89,7 @@
mysqldump "$dbuser" > "/data/project/$tool/database_backup.sql"
echo "Removing db access of $tool"
echo "drop database $dbuser;" | mysql mysql
+ fi
fi
if [ ! -d /data/project/removed_tools ];then
@@ -60,6 +109,7 @@
else
cd /data/project/removed_tools
tar -zcvf "$tool.tar.gz" "$tool"
+ chmod 600 "$tool.tar.gz"
if [ -f "/data/project/removed_tools/$tool.tar.gz" ];then
echo Deleting project folder
rm -rf "/data/project/removed_tools/$tool"
@@ -88,4 +138,8 @@
rm /data/project/.system/webservers.lock
+if [ -f /data/project/.system/cache/localdb-$tool ];then
+ rm /data/project/.system/cache/localdb-$tool
+fi
+
echo "All data for $tool were cleaned"
--
To view, visit https://gerrit.wikimedia.org/r/104397
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Id28309442df5a149031962ea9e6953e8280a41b6
Gerrit-PatchSet: 1
Gerrit-Project: labs/toollabs
Gerrit-Branch: master
Gerrit-Owner: Tim Landscheidt <[email protected]>
Gerrit-Reviewer: Petrb <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits