Restoring a deleted site from backup

What issue or error are you experiencing?

I accidentally deleted a number of sites from Local. I have the site files—the WP installation, theme files, etc—but not the database. However, I have a recent backup (a mirror, not a Time Machine backup) of my hard drive. Would it be possible to locate the container files on the backup and restore the sites that way?

What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

System Details

  • Local Version: Current version is Version 8.2.1+6583. I was on a slightly earlier version (8.1.9?) when I deleted the sites, though.

  • Operating System (OS) and OS version: macOS 12.5 (21G72) (Monterey )

Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)

Not sure if the logs would be helpful, since I know what happened, but I can add them if needed.

Security Reminder
Local does a pretty good job of scrubbing private info from the logs and the errors it produces, however there’s always the possibility that something private can come through. Because these are public forums, always review the screenshots you are sharing to make sure there isn’t private info like passwords being displayed.

Hi @csilverman

I’ve never tried it myself but essentially what Local needs to import a zip file for example is WP-Content and SQL bundled together. So if you’re able to find a DB file on the Mirror you can then combine that with what you have from the site files. Alternatively, what you’re looking at is a more manual restore. You could spin up a new, blank site in Local and then manually move over/import your items. The steps would look like this:

Manually Import a Local Site

I hope that helps but let us know if you have any other questions!

Hi Nick. Unfortunately I don’t have the SQL files, since I deleted the sites before I exported them. I still have the Docker containers on a backup drive, which would have the SQL databases, but I’m not sure where to put those containers so Local can find them.

Do you know where Local stores the containers for sites?

  • Chris

Hey @csilverman – I’m a little confused – the latest versions of Local don’t use Docker.

Older versions of Local made use of docker to host the sites, however, starting with the 5.x line, we no longer use docker and instead run the server processes directly on the host machine.

You mention having a mirror of the sites, can you expand on that a little?

Basically, there are roughly two ways to try and salvage a site. The first way is the safer route, and what you should try first while the second route is a little risky and might not work.

1. Locate and restore the sql dump file in the Local Sites folder

This is basically what Nick mentioned. When a Local site is stopped, the DB is exported to a folder at a location like this:

/Users/[username]/Local Sites/[sitename]/app/sql/local.sql

If you have a mirror of the drive, then I would try to restore the Local Sites folder. For the sites that have a local.sql file, you can zip up the files and sql dump using the help doc link from Nick:

2. Maybe use the raw DB files

While the ~/Local Sites folder is the safer place to go for restoring a site, Local stores the raw MySQL database files in the run folder of Local’s user config folder. This is located at:

/Users/[username]/Library/Application Support/Local/run

Each site’s raw files are contained in a folder with the site’s id. Within each of those folders is a mysql/data folder:

If you do have that run folder (and hopefully the raw DB files aren’t corrupted), then the rough process for restoring the sites would look like this:

For each site you want to restore…

  1. Create a new, plain WP site.
  2. Copy any files to this new site (ie, wp-content, uploads/media/plugins/etc)
  3. Stop the site and quit Local. very important! We need the mysql daemon to not be running!
  4. You should see a new folder within the ~/Library/Application Support/Local/run folder with a site id for the site.
  5. Replace that site’s mysql/data folder with the mysql/data folder from the backup you have.
  6. Start Local and start the site and verify things are working

There are lots of things that could go wrong, so be careful and go slow!

For example, one thing I could imagine as being a problem is if the table prefix is different from the default wp_ prefix. You might need to update the wp-config.php file for the site with whatever prefix is used with the DB files.

Anyway, hope that helps give you some options for proceeding. Let us know if you get things working or have any pointers that might help the next person.

1 Like

Hi Ben. Thank you very much for your suggestions here. I’ve had to be offline, so I haven’t had a chance to try these yet, but these sound promising. Really appreciate the help.

  • Chris

Hi Ben. I just wanted to say thank you again for your help here. I think I was confused earlier; I’d forgotten that Local no longer used Docker. I took a look at my backup drive, and the sites didn’t have local.sql files for some reason. Your suggestion about restoring the raw DB files worked very well, though. I was able to get everything back.

Thank you!!

  • Chris

Glad to hear that @csilverman! Thank you for coming back and updating us :green_heart:

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.