As I mentioned on talkPress #004, here are the scripts. This page is still a working in progress. I was thinking to put them on repository, but it’s hard to generalize these scripts to fit everyone’s environment. Therefore, I decided to post my nearly original scripts in this page. I will keep updating them, if necessary. You are also welcome to modify them and give me your generous feedbacks.
Environment
I have to preset what the environment these scripts are suitable to be used. You may need to make some modifications, or ask me to do that, I will see if anything that I can help.
Hosting Server
- Provider: Bluehost – this may not really matter.
- Path to root directory of web files:
~/public_html - Path to root directory of WordPress:
~/public_html/blog - SSH access: allowed
Local Server
It doesn’t really need to have a local web server, but that can reduce debugging time and efforts to make things working. You may just have a directory to store web files.
- Linux and Mac OSX should work, Windows?
- Path to root directory of web files:
/path/to/webroot - Path to root directory of WordPress:
/path/to/webroot/blog - VCS: Subversion or Mercurial
About the VCS
I personally do not recommend you check out WordPress’ repository. You should create your own repository, which contains web files, WordPress files, your template files and plugins files. The meaning of use of VCS is to have information of changes. If you check out WordPress’ repository, then you can not put other files under control.
This is a trade-off, use of WordPress’ repository is easy for upgrading WordPress, just svn update, then done. But you don’t have detail version-to-version diff for your files.
Scripts
Synchronization Scripts – sync
#!/bin/bash
# Author : Yu-Jie Lin
# Website : http://www.livibetter.com
# Creation Date: Unknown - 2008-01-13T04:14:54+0800
# Last Change : 2008-01-15T12:34:50+0800
#
# Note: this script passes arguments to rsync
DEST=username@yourdomain.com:public_html
SRC=/path/to/webroot/*
excludes=(\
".htaccess" \
"*.swp" \ # Vim
"*.log" \
".DS_Store" \ # OSX folder
".svn" \ # Subversion
".hg" \ # Mercurial
"wp-content/uploads" \
"sitemap.x*" \ # If you have Google Sitemap plugin
"*bak" \
"*~" \ # gedit files
"*.pyc" \ # Python bytecode files
"wp-config.php" \ # config file for WordPress
"config.php" \ # config file for bbPress
"error_log" \
)
excludeStr=""
for e in ${excludes[@]}; do
excludeStr=$excludeStr"--exclude=$e "
done
cmd="--progress --stats --compress --rsh=/usr/bin/ssh --recursive --times $@ $excludeStr $SRC $DEST"
echo "rsync $cmd"
echo -n "Do it (y/N)?"
read ans
if [[ $ans == [yY] ]]; then
rsync $cmd
fi
This script gives you a chance to make a decision before synchronization. Change the DEST and SRC to fits your environment. Add or remove those exclusions. If you don’t specify a path to DEST, then the destination usually is your home directory on server. If specify one like yourdomain.com:path/to/something or yourdomain.com:/path/to/theotherthing, the results are ~/path/to/something and /path/to/theotherthing, respectively on server. You must specify the username if you are using different local username than your username on server. You will be asked for a password for logging in.
DB backup from bluehost – bk-bh-databases
#!/bin/bash
# Author : Yu-Jie Lin
# Website : http://www.livibetter.com
# Creation Date: Unknown - 2008-01-13T05:13:06+0800
# Last Change : 2008-01-13T06:02:49+0800
BACKUP_ROOT=~/tmp
DEST_DIR=$BACKUP_ROOT/mysql
SERVER_IP=1.2.3.4
BASE_URI=http://$SERVER_IP:2082/getsqlbackup
# Create dirs
mkdir -p $DEST_DIR
cd $DEST_DIR
# Date tag
DATETAG=`date -u +%Y-%m-%dT%H-%M-%S`
function SetUserPass {
read -p "username:" user
read -p "password:" -s pass
echo
# Preparing .wgetrc
touch ~/.wgetrc
chmod 600 ~/.wgetrc
echo "http-user = $user" > ~/.wgetrc
echo "http-password = $pass" >> ~/.wgetrc
}
function DL {
# Starting to download
wget $1
if [ $? -eq 0 ]; then
if [ "$2" != "" ]; then
# Attach the date tag
base=$(basename $1)
mv $base "$(basename $1 $2)-$DATETAG$2"
fi
else
echo "Failed to download $(basename $1)"
fi
}
SetUserPass
DL $BASE_URI/dbname1.sql.gz .gz
DL $BASE_URI/dbname2.sql.gz .gz
rm ~/.wgetrc
echo Done.
This script will ask for username and password for logging in cPanel of Bluehost. It stores username and password to ~/.wgetrc, after download, it removes that file. It also attaches date tag to the downloaded files. You can get the server IP by logging into cPanel, then the IP is at the address bar of your web browser. I think (100% not for sure) this may be used on other hosting providers if they use cPanel, too. This can also download the daily and weekly backups, just change the URI.
Restoring to local server databases
soon…
Finding and deleting obsolete files of WordPress
soon…