509.949.2162 jeremy@bondbyte.com

This assumes you’ve followed my other blog post about creating a docker environment with a network, Nginx Reverse Proxy and LetsEncrypt NginX Reverse Proxy Companion.

#Restore Script
#Do this on the host. It will unballz the files. 

# Find and Replace these Values. I will roll this up into a better bash script later. Promise.
#-------------------------------------------#
#-Find Value------Replace Value Sample------#
#-------------------------------------------#
# instancename 	= contoso
# backupname 	= glaciersales.2023-12-30-1849.tar.gz
# sitename  	= html
# siteurl	= contoso.com
# tobackpath  	= /home/sudouser/backup
# dbuser	= wpuser
# dbpass	= password
# dbrootpass	= rootpass
# dbname	= wp_precisionpaving
# dbfilename	= database




#HOST: Create new directory
mkdir /usr/WordpressBackups/instancename

#HOST: Extract the zball
tar -xf backupname -C instancename

#HOST: Create Docker Backend
#Create WordPress Database Instance [For new Sites]
docker run --name wpbe-instancename --net wpn-main -e MARIADB_ROOT_PASSWORD=dbrootpass -e MARIADB_USER=dbuser -e MARIADB_PASSWORD=dbpass -e MARIADB_DATABASE=dbname -d --restart always mariadb

#HOST: Create Docker FrontEnd
#Create WordPress Front End [For new Sites]
docker run --name wpfe-instancename --net wpn-main -e WORDPRESS_DB_HOST=wpbe-instancename:3306 -e WORDPRESS_DB_NAME=dbname -e WORDPRESS_DB_USER=dbuser -e WORDPRESS_DB_PASSWORD=dbpass -e VIRTUAL_HOST=www.siteurl,siteurl -e LETSENCRYPT_HOST=www.siteurl,siteurl -e LETSENCRYPT_EMAIL=certs@contoso.com -d --restart always wordpress

#HOST: Connect to Docker Frontend Container


#Docker FE:
docker exec -it wpfe-instancename bash

Docker BE: 
rm -dr /var/www/html/wp-content/uploads
rm -dr /var/www/html/wp-content/themes
rm -dr /var/www/html/wp-content/plugins

#HOST: Copy Uploads
docker cp /usr/WordpressBackups/instancename/var/www/instancename/wp-content/uploads wpfe-instancename:/var/www/html/wp-content/uploads

#HOST: Copy Theme
docker cp /usr/WordpressBackups/instancename/var/www/instancename/wp-content/themes wpfe-instancename:/var/www/html/wp-content/themes

#HOST: Copy Plugins
docker cp /usr/WordpressBackups/instancename/var/www/instancename/wp-content/plugins wpfe-instancename:/var/www/html/wp-content/plugins

#HOST: Copy Database to Backend
docker cp /usr/WordpressBackups/instancename/database/dbfilename.sql wpbe-instancename:/home

#HOST: Connect to Docker Backend Container
docker exec -it wpbe-instancename bash

#Docker BE: 
mariadb -u dbuser -pdbpass
mysql> use wordpressdb;
mysql> source /home/dbfilename.sql;

#Docker BE > Maria DB:
Exit

#Docker BE: Exit to Host
Exit