We recently had BOTs setting up accounts on our website, 2000 or so.

We accidentally clicked delete all instead of delete all visible and lost about half of our accounts.

I have a database backup from a few weeks ago that I can use, what would be the best way to get the customers from the old database without effecting the customers that weren't deleted?


I would do following:

  • create a new temp installation from the backup.
  • Export customers
  • Delete all customers from current site
  • Import from the exported csv file
| improve this answer | |
  • Will the customers still be able to see the orders on their accounts when they get imported doing it this way? – GerPhysio Jun 26 '18 at 17:03
  • I'm not convinced they would be able to. But Devtpes' solution is the best one I can think of too. – Craig Jun 26 '18 at 17:04
  • 1
    No they won't be able to see the orders. In the sales_flat_order table is a column customer_id. After the import, update this column with the new customer-IDs. For mapping, you can use the customer's email address which is present in the customer_entity and the sales_flat_order tables – simonthesorcerer Jun 26 '18 at 18:29
  • How would I do this for 2000 or so customers? Is there a mysql command I could run to do this? – GerPhysio Jun 26 '18 at 21:39
  • You can halve your work by only importing the deleted customers. For that you have to export customers from current site and new temp installation then compare both and difference will be imported into current site, after that you can associate newly added customers to the orders. To speed up the work you can use some ready made plugin such as marketplace.magento.com/magebright-magebright-assignorder.html (check the suitability first as I've never used it). – Devtype Jun 27 '18 at 8:22

The deleted customers' orders are still in sales_flat_order only the customer_id is reset to NULL and orders set to archived. That means some of their info is still there.

Curiously after this accident happened literally during processing an order, Magento created the customer again with a new ID and the order went on like nothing was wrong. Thankfully (for me) I was working on a migration tool so I have a list of customer_ids with email, name, and their original password hash. Working out the steps to manually add them now.

Edited to add: I have accomplished as much as a repair as I deem practical for now.

  • Got list of customers from the Xfer database whose IDs were up to 1053 (the lowest number remaining in the customer list).
  • Used Mage::getModel() and $customer to add the deleted customer back to Magento 1.
  • Got the new customer id from the newly added customer so I can match to the old customer ID from the Xfer database.
  • Updated customer_entity to fix created_at, the website_id, and store_id.
  • Updated sales_flat_order to set the customer_id where the email matches the one from the Xfer database.
  • Updated sales_flat_invoice to find the previous customer ID and change to the new customer ID.
  • Inserted the password hash from the Xfer database back into customer_entity_varchar.


  • The customers reappear on the manage customers list, only now at the top.
  • Previous sales appear in "purchases".
  • The "orders" tab is blank. Not exactly sure how that tab is populated and not going to pore over the code unless people complain.
  • You'll need to manually make a query to update the website and store IDs. The create customer Mage call I used ignored what I put in.
  • Created_at is broken, but it's not exactly awesome anywhere in our Magento.
| improve this answer | |
  • 1
    orders tab can be fixed by updating customer_ids in the sales_flat_order_grid table – robotik Apr 26 at 12:32

I would only work in phpMyAdmin:

  • restore the backup in new database
  • copy customer_entity, customer_entity_* tables (if addresses got deleted too then customer_entity_address* tables too) from new database to old database renaming them like *_2 on the way
  • insert into customer_entity 
    select * from customer_entity_2 
    where entity_id not in (select entity_id from customer_entity)
  • do the same for all the moved tables

I guess that way all the old connections that are based on customer_id would work (like orders and such)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.