How can we help?

Restore a SnapShooter WordPress backup to Different Location

Learn how to restore your SnapShooter WordPress/Gridpane to a different location

Simon Bennett]
Simon Bennett
Last Updated: Mar 2, 2021
Table of Contents

Our one-click restore process is designed to get your existing site back up and running asap. However, you may want to restore a backup to a different location. We explain how you can do this and create a script to get started.

First, you need to grab the URLs SnapShooter shows you for backups. These have an expiry date of one hour and should be kept private, as anyone with the link (within the one hour window) can download your backup.

# Install the script on your server

nano /tmp/snapshooter-wp-restore

# © 2017-2021 SnapShooter Limited.
echo "# © 2017-$(date +"%Y") SnapShooter Limited."
echo "# Terms and Conditions"
echo ""

echo "Which Directory do you want the backups to restore to  (/var/www/sitename)"
read wp_dir
echo Backups will be restored to $wp_dir
echo ""

echo "Please give us the download url for the MYSQL database"
read wp_mysql_url
echo ""

echo "Please give us the download url for the ASSETS database"
read wp_assets_url
echo ""

rm /tmp/restore.tar.gz
curl $wp_assets_url -o /tmp/restore.tar.gz

tarDirectory=$( cat /tmp/restore.tar.gz | gunzip - | tar -tvf - | head -1 | rev | cut -d " " -f 1 | rev)
strip=$(awk -F"/" '{print NF-1}' <<< "${tarDirectory}")
echo Found the DIR in tar to be $tarDirectory

echo Restoring site now
cd $wp_dir
cp $wp_dir/wp-config.php /tmp/wp-config.php.back
cat /tmp/restore.tar.gz | tar -zxf - --strip=$strip
rm $wp_dir/wp-config.php
mv /tmp/wp-config.php.back $wp_dir/wp-config.php

echo ""
rm /tmp/restore.tar.gz

echo Restoring Database

MYSQL_USERNAME=$(cat wp-config.php | grep DB_USER | cut -d \' -f 4)
MYSQL_PASSWORD=$(cat wp-config.php | grep DB_PASSWORD | cut -d \' -f 4)
MYSQL_HOST=$(cat wp-config.php | grep DB_HOST | cut -d \' -f 4)
MYSQL_PORT=$(php -r "echo explode(':','$MYSQL_HOST')[1] ?? 3306;")
MYSQL_DATABASE=$(cat wp-config.php | grep DB_NAME | cut -d \' -f 4)

curl $wp_mysql_url --output - | gunzip - | mysql -u $MYSQL_USERNAME -p$MYSQL_PASSWORD -h $MYSQL_HOST -P $MYSQL_PORT $MYSQL_DATABASE

echo Backup Restored

Give the script execute permissions

chmod +x /tmp/snapshooter-wp-restore

# Finding your download URLs

SnapShooter will generate download links for all the files in your backup. We generate them with a signature to keep them secure, which also defaults too one per hour.

Find the backup you wish to restore and press the Manage button.

Manage Backup

You will notice you have two backup files for a WordPress single backup, if you're doing multi-backup Wordpress or GridPane backups you will see many files and will need to find the matching site names (you can sort by name or size). View Backup Files

For the files you need to press copy link, and it will generate you a unique download link (1 hour)

Copy Download Link

# Run the Script

Now you are ready to run the script on the server you wish to restore on


When you run the script you will get three prompts

  • The directory of the WordPress site you wish to overwrite e.g /var/www (no trailing slash)
  • The SnapShooter URL for the Database
  • The SnapShooter URL for the file system assets

Running Restore Script

You can now login to your site. You may need to manually correct the WP config for the correct URL.

Did you find this article helpful?