Restore Site from a Backup into Shadow

Sometimes it may be easier to restore the site from a backup, and set the retrieved copy up and running in the staging (shadow) environment instead. Here you'll find instructions on how to retrieve the necessary files, and then transfer them into the staging environment.

The restoration is done on command line (see instructions for SSH connection).

Please note that shadow environments are not automatically backed up. However, it is possible to take manual backups in a shadow with the command wp-backup. 

Retrieving files from a backup in the production environment

First you need to connect to the production environment with SSH and retrieve the wp-content directory and the site's database from a backup. You can get a list of all available backups with the command wp-backup-status. The command will print a numbered list of all available backups. The restoration itself will be done with the command wp-backup-restore. The command needs the correct backup's id number as a parameter, this number can be found on the left side of the backup list, and in this example it is 1:  

wp-backup-restore 1 

This command will restore the backed up files to the site's /tmp directory, in a folder that is (in this case) named as "backup-restore-1". Relevant directories inside it are db and wordpress. Next we will move the database file and the wp-content directory to the root of /tmp directory, and compress them to be moved to the shadow environment. 

1. The database file can be found from path /tmp/backup-restore-1/db/. There are most likely two files in here: one with .sql ending and another with .sql.orig ending. The right one is the .sql file, example_a1b2c3.sql in this example. Move the file to the root of /tmp directory: 

mv /tmp/backup-restore-1/db/example_a1b2c3.sql /tmp 

2. The site files can be found under wp-content directory, which is in path /tmp/backup-restore-1/wordpress/htdocs. Move that directory under /tmp as well:

mv /tmp/backup-restore-1/wordpress/htdocs/wp-content /tmp 

3. Move to the /tmp directory and pack both of these files as a compressed directory to be moved to the shadow (the compressed folder is called shadowrestore.tar.gz):

cd /tmp tar -czvf shadowrestore.tar.gz wp-content example_a1b2c3.sql 

Now it's time to move to the shadow environment.

Transfer the backup into shadow

Next we'll connect with SSH to the shadow environment. There we'll fetch the file we created earlier with the rsync command. The port number (12345) must be replaced with the production environment port number of your site, and the user and host address also need to be changed to match your own site's credentials. In the command below all of these are replaced with example values, so you will need to edit the command before running it. You can find your site's SSH/SFTP credentials in the email Seravo sent you when you ordered the plan in the first place. If you don't have these credentials, you can ask for them from our customer support

1. Retrieve the compressed files from production:

rsync -avz -e 'ssh -p 12345' username@example.fi-r.seravo.com:/tmp/shadowrestore.tar.gz /tmp 

At this point the command will give a warning: "the authenticity of host can't be established" and asks you whether you really want to continue. You can type in "yes" and press enter, after which the command will ask you for a password. This password can also be found in the aforementioned email. 

2. Move to the shadow's /tmp directory and unzip the compressed files: 

cd /tmp && tar zxvf shadowrestore.tar.gz 

3. Remove the existing wp-content directory, move the wp-content from the backup in its place, import the database and finally empty the server cache. 

rm -rf /data/wordpress/htdocs/wp-content 
mv wp-content /data/wordpress/htdocs/ 
wp db import esimerkki_a1b2c3.sql --skip-optimization 
wp-purge-cache

You can also run the commands together as one command like this: 

rm -rf /data/wordpress/htdocs/wp-content && mv wp-content /data/wordpress/htdocs/ && wp db import esimerkki_a1b2c3.sql --skip-optimization && wp-purge-cache 

Now your shadow environment should have the correct back up restored in it. 

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