Restoring from a Backup

As the customer of Seravo's premium hosting and upkeep you can always contact our customer support (email help@seravo.com) when a backup restore is needed on your WordPress site. Restoring the site from a backup is a part of our routine customer support, free of charge. If need be, below you'll find instructions on how to restore backups yourself.

To restore the site from a backup file, first connect to your site with SSH. Restoring a backup is done by running commands on the command line. To restore a backup, you usually need to retrieve both the site files and it's database. It is also possible to restore the whole site with just one command, but this option should only be used if you are absolutely certain that the database can be restored to it's previous state. You can also restore only the site's plugins or themes if you wish. 

The latest backup can always be found in the /data/backups directory. From this directory you can copy the latest backed up version of your files with the cp-command to the desired location.

Restoring the whole site at once (wp-content + database) 

If you are sure that it is safe to restore both the site files and the database, you may use this option. NOTE! If your site has an online store (WooCommerce), you need to be careful when restoring the database, because orders might get lost in the process. So unless you are absolutely sure of what you are doing, do not use this option. 

1. Connect to your site with SSH (see: How do I connect to my WordPress site with SSH/SFTP?)

2. Before you begin, it is advisable to take a fresh backup with the command wp-backup.

3. If you want to, you can also compare the files of the backups. The command wp-backup-list-changes lists all files that have changed between present and the latest backup. By using this information you can restore a specific portion of the site. Close the list with Ctrl+Z (or Cmd+Z) or pressing Q.

4. The backup files can be found in the directory /data/backups. The file marked "current mirror" is always the latest backup. You can create a numbered list of all available backups with the command wp-backup-status:

wp-backup-status

5. Next we will restore the desired backup with the command wp-backup-restore. For this command we give the correct id number (the number on the left side of the list) as a parameter and because we wish to restore the whole site with one command, we will also use the --in-place flag. 

wp-backup-restore 2 --in-place

6. After running this command, a question will be printed on the screen. You need to answer it before the process will move forward. If you wish to proceed, write y and press enter (restore process continues). If you do not want to proceed, write n and press enter (restore process is aborted). 

7. Note that the restore process may take some time, especially if you are restoring a big website. Restoring big databases can sometimes take even several hours. 

8. If you get a "Success!" -message in your terminal, it means that the backup restore was successful and the site should now have the wp-content and database from the backup you chose earlier. You can now flush the site's cache by running wp-purge-cache and check if the backup restore did what you wanted it to do. 

Restoring from backup without restoring the database

Sometimes it might be better to restore only a part of the site, for example wp-content directory or just the plugins. This is also possible, but it needs a bit more manual work. 

1. Connect to your site with SSH. 

2. Before you do anything else, take a new backup with the command wp-backup, just in case.

3. Run the command wp-backup-status and check what is the id number of the backup from the date you need (on the left hand side of the window). 

4. Run the command wp-backup-restore with the desired id number, for example like this: 

wp-backup-restore 2 

The command will restore the desired backup into a temporary folder, in this case to /tmp/backup-restore-2/. The number in the directory name is determined by the backup's id number. After a successful restore the command will print out the following message:

Restoring to /tmp/backup-restore-2... Success! Backup available at /tmp/backup-restore-2 You can now view and copy the files you want to restore. Current database can be replaced with the backup by running 'wp-db-load /tmp/backup-restore-2/db/example_a12345.sql'

So now you are able to navigate to this directory and move the desired directories or files to replace the existing ones. If you, for example, would want to replace the current wp-content directory here's how that would be done: 

1. Rename the current wp-content directory with some descriptive name 

mv /data/wordpress/htdocs/wp-content /data/wordpress/htdocs/wp-content-broken 

2. Move the wp-content from the backup folder to replace the old one 

mv /tmp/backup-restore-3/wordpress/htdocs/wp-content /data/wordpress/htdocs 

3. If this fixes your problem and everything works fine, you can now delete the old wp-content folder 

rm -rf /data/wordpress/htdocs/wp-content-broken 

This same logic can be applied to any other directory in the backup folder, so if you want to replace plugins directory, just tweak the commands to use that one instead and so on.  

If in this situation you still need to restore the site's database too, you can use the command that was printed out earlier. Remember to check that the directory and file names are correct!   

wp-db-load /tmp/backup-restore-2/db/example_a12345.sql

Restoring from a backup in a shadow environment

Sometimes it may be necessary to restore the site from a backup, and set it up and running in a staging environment instead. As the staging environment is a separate instance, it can be used for troubleshooting or retrieving lost data. See instructions in a separate article here!

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.