Bogiecom.com
  • About
  • Magento
  • Sitecore
  • WordPress

Quick Way to Archive a WordPress Site

Posted on December 16, 2013 by bc-admin

So if you need a quick way to archive your WordPress install and you have shell access through SSH, this script could help you do that quickly.  You will need to make sure that ‘zip’ is installed (of course you could also modify the script below to use something like gzip or bz2 or whatever).

So the steps to getting this to work are:

  1. Upload the script below to the server as “wordpress-arch.sh”
  2. Make it executable by running “chmod +x wordpress-arch.sh”
  3. Execute the script by running “./wordpress-arch.sh” or “/bin/sh /path/to/script/wordpress-arch.sh”
  4. Specify a file name without the zip extension
  5. Then provide the full path to the WordPress root folder

The script will then copy all of the existing files to a directory with the same name as the file name you specified.  Next it will find the wp-config.php and find the database connection info.  Then runs mysqldump and saves a .sql to the root of the copied files. Zips up that directory to a zip archive in the same directory the script was executed from, and deletes the copy of the wordpress installation.

Some assumptions it makes is that you want to put the database dump in the root of the archive, and that you want to clean out your database username and password before passing it to someone else for install.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# !bin/bash
# wordpress-arch.sh
# run 'chmod +x wordpress-arch.sh' to allow for execution
# execute by running './wordpress-arch.sh' or '/bin/sh wordpress-arch.sh'
 
# get unknown info
read -p "Enter final archive file name without the extension (.zip) " archPath
read -e -p "Enter the full path to the root of the wordpress installation " indir
 
# find database information
WPDBNAME=`cat $indir/wp-config.php | grep DB_NAME | cut -d \' -f 4`
WPDBUSER=`cat $indir/wp-config.php | grep DB_USER | cut -d \' -f 4`
WPDBPASS=`cat $indir/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`
 
# echo the Wordpress config info
echo "Found this database information"
echo "DBNAME $WPDBNAME"
echo "DBUSER $WPDBUSER"
echo "DBPASS $WPDBPASS"
 
# make a new directory for the migration
mkdir $archPath
 
# copy all of the files to a new directory
cp -rfv $indir/* $archPath
 
# dump database using the found wordpress database settings
mysqldump -u$WPDBUSER -p$WPDBPASS $WPDBNAME > "$archPath/$WPDBNAME.sql"
 
# get rid of Wordpress Database User & Password before zipping to archive
sed -ie "s/$WPDBUSER//gI" $archPath/wp-config.php
sed -ie "s/$WPDBPASS//gI" $archPath/wp-config.php
 
# zip up all of the files
zip -r "$archPath.zip" $archPath
 
# remove the copied files
rm -rf $archPath

I know, I know… pretty basic. However, it’s something I needed, and maybe just maybe someone else does as well. I might change this up to make it an automated migration script that could deploy to a remote server, install all of the files, import the database, and setup an Apache host. But for now, this is all I need. 🙂

Posted in Bash, Linux, Shell Scripting, Wordpress |
« SED find and replace string, then revert backup.
Tree Menu Traversal in C# Queryable »

Pages

  • About
  • Magento
  • Sitecore
  • WordPress

Archives

  • January 2017
  • December 2013
  • November 2013
  • February 2013
  • January 2013
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • November 2011
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • September 2009

Categories

  • .NET
  • Air Force
  • Apache Configuration
  • Bash
  • C#
  • Comma-Delimited
  • Custom Field Validator
  • Date Format
  • Dump Files
  • Files
  • Grep
  • Grooveshark
  • HTML
  • Image Resizing
  • Imagick
  • Integration
  • jQuery
  • Konami Code
  • Linux
  • Magento
  • Magento Third Party CMS Integration
  • Mini Shuttle
  • Miva Merchant 5.5
  • MySQL
  • PHP
  • Powershell
  • Regular Expressions
  • Rename-Item
  • Sed
  • Shell Scripting
  • Sitecore
  • Strings
  • Uncategorized
  • Updating Product Attributes
  • Video Games
  • Wordpress
  • X-37
  • XML
  • YUI Konami Event

CyberChimps WordPress Themes

© 2008 - 2016 Bogiecom.com