2

My site got hacked and I had an online service clean it out. However, it now has over 150,000 user accounts, the bulk of which have no role assignment. How do I delete these accounts and their content?

PS: Drush solutions are appreciated and welcome, but for now I would prefer non-Drush answers.

I tried suggestion 1 at How to delete 'blocked' users in bulk? but both options are time consuming and the VBO module seemed to hang. Suggestion 2 seems to be the fastest option, but the /core/modules/user/user.admin.inc file doesn't exist in Drupal 8.7.

0

1 Answer 1

4

I just had to do this recently. I found the easiest thing was to build a list of the emails addresses to remove in a text file.

_remove_user_emails.txt

[email protected] [email protected] [email protected] 

Then process them with the simple script below:

remove_users.sh

IFS=" " pwd for user in `cat _remove_user_emails.txt` do echo "Cancelling user: $user" ./vendor/bin/drush -y user-cancel ${user} done 

You can derive your list however you'd like. I often use phpmyadmin and just write a query for what I need and export it. Something like this:

SELECT DISTINCT u.mail FROM users u LEFT JOIN users_roles ur on u.uid = ur.uid WHERE u.uid > 1 AND u.status <> 0 AND ur.rid IS NULL 
4
  • With over 150000 user accounts, it doesn't seem feasible to write the email addresses in a text file, and then delete the user accounts with Drush. Commented Sep 17, 2021 at 20:02
  • @Ryan, I tried your suggestion on my test site, I had to adjust for execution time, etc, etc in my config files...something I don't have access to on the live site. Cancelled process after about 2hrs of running. Thanks, but I hope I can get a faster and more efficient solution. Commented Sep 17, 2021 at 23:26
  • In order to remove users, you need to run all the hooks. I found drush to be the fastest way to do that. Perhaps instead of putting 150k users in a file, instead try a smaller set like 10k users. My site had about 50k users and we removed 30k over about 15 hours YMMV. Not sure why you had to edit the exec time, this is a bash script, that will run php over and over vs one long thread. Commented Sep 18, 2021 at 0:48
  • 1
    Why cancel the script execution after two hours? I'd recommend leaving it running overnight. Commented Sep 20, 2021 at 13:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.