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 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).

Retrieve files from a backup in production environment

First, let's connect with SSH to the production environment and retrieve the wp-content directory from the backups. The available backups can be listed with the command rdiff-backup -l /data/backups/data. In this example, the name of the directory is 'wp-content-restore-2022-03-02'. Edit the following command to your needs:

cd /tmp && rdiff-backup -r 2022-03-02 /data/backups/data/wordpress/htdocs/wp-content/ wp-content-restore-2022-03-02

Also the site's database needs to be retrieved. List the files in directory /data/db, and you'll see the name of your database:

ll /data/db

The name of the database is unique and generated from the name of your site, so you need to edit the following command to correspond that name. In this example, the name of the database will be exampl_a1b2c3.sql. Retrieve the database from the desired date/time by editing the following command:

cd /tmp && rdiff-backup -r 2022-03-02 /data/backups/data/db/exampl_a1b2c3.sql db_restore-2022-03-02.sql

Then we'll create a compressed file, in which we will include the wp-content directory as well as database we just retrieved:

tar czvf shadowrestore.tar.gz wp-content-restore-2022-03-02 db_restore-2022-03-02.sql

That's it for the production environment! Next we'll connect into the shadow environment, further instructions below.

Transfer the backup into shadow

Next we'll connect 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. Make note of the server location as well in the address (us, de, se, or some other such as fi-r or fi-t):

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

After this we can ensure we are in /tmp/ directory and unzip the compressed file:

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

Tämän jälkeen seuraavalla komennolla voidaan uudelleennimetä hakemistot ja poistaa vanha wp-content-hakemisto.  Then we can rename/move the directory names and remove the old wp-content directory. In addition to this, the database is imported (with command wp db import) and server cache is flushed (wp-purge-cache):

rm -rf /data/wordpress/htdocs/wp-content && mv wp-content-restore-2022-03-02 /data/wordpress/htdocs/wp-content && wp db import db_restore-2022-03-02.sql --skip-optimization && wp-purge-cache
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.