Extract a WPBackup tar file into a Apache2

Extract a WPBackup tar file into a Apache2

Extract a WPBackup tar file into a Apache2

No Comments on Extract a WPBackup tar file into a Apache2

During my internship at MNWorks.dk I created a script to extract a WPBackup tar file into a Apache2 server in 1 click. This is the first version of the script, and there are a lot of room for improvement.

This script is created in house, for use in testing changes made to company websites in a virtual production environment.
It works well for my use, but will definitely need to be changed in order to function correctly for other cases/servers.

Requirements

  • Debian/Ubuntu based system
  • Dropbox daemon installed and running
  • LAMPP stack installed and running
  • Symlinked /var/www/htdocs/ to /home/USERNAME/htdocs
  • Using WPbackup plugin and sync it to Dropbox

 

#LOGIN INFORMATION:
DBHOST="localhost"
DBPORT="3306"
DBNAME="INSERT_USERNAME"
DBUSER="INSERT_USERNAME"
DBPASS="INSERT_PASSWORD"
#Here we insert URL from the live site
OLDURL="OLD_URL"
NEWURL="localhost/htdocs/FOLDER_NAME/"
cd /home/USER/htdocs/
#clean up old backups
/opt/lampp/bin/mysqldump -u$DBUSER -p$DBPASS --no-data $DBNAME | grep ^DROP > drop.sql
/opt/lampp/bin/mysql -u$DBUSER -p$DBPASS --database=$DBNAME < drop.sql
rm drop.sql
#rm -rf ./backwpup*
rm -rf ./mnworks
mkdir /home/USERNAME/htdocs/mnworks/ && tar -xzf $(ls /home/USERNAME/Dropbox/MN-Works-ApS/backwpup_95f118_??????????_????????.tar.gz | 
tail -n 1) -C /home/USERNAME/htdocs/mnworks/
/opt/lampp/bin/mysql --local -u$DBUSER -p$DBPASS $DBNAME < /home/USERNAME/htdocs/DATABASE_NAME.sql
echo "Updating databse"
sleep 3
echo "Updating links"
/opt/lampp/bin/mysql -u$DBUSER -p$DBPASS -h$DBHOST -P$DBPORT -v -v -v -e "use $DBNAME;
UPDATE wp_posts SET guid = replace(guid, '$OLDURL', '$NEWURL');
UPDATE wp_posts SET post_content = replace(post_content, '$OLDURL', '$NEWURL');
UPDATE wp_options SET option_value = replace(option_value, '$OLDURL', '$NEWURL');
UPDATE wp_postmeta SET meta_value = replace(meta_value, '$OLDURL', '$NEWURL');"

echo "
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /htdocs/WEBSITE_NAME/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /htdocs/WEBSITE_NAME/index.php [L]
</IfModule>
# END WordPress" > /home/USERNAME/htdocs/WEBSITE_NAME/.htaccess

 

The script will Extract the latest tar file from the Dropbox folder, copy the backup to the htdocs folder, it will then wipe the MySQL database clean and update it with the backup sql dump file. In the end it will echo the wordpress config file into the directory.

This script works well for my use, but will definitely need to be changed in order to function correctly for other cases/servers. Hope someone will make good use of it!

Martin Jørgensen

Martin Jørgensen

Got my degree from EAL in 2012 as an IT-Technologist with specialty in network. I enjoy living in a century where I can earn a living doing my hobby. Material I publish here are often part of my small projects.
Martin Jørgensen

Latest posts by Martin Jørgensen (see all)

Related Posts

Back to Top