Slide 30
Slide 30 text
#!/bin/sh
SUSER="alantaifirestar"; # SSH user
SHOST="tomjn.com"; # remote server
SDIR="/home/alantaifirestar/tomjn.com/"; # remote folder
LDIR="/srv/www/tomjn.com" #local folder
echo 'starting rsync'
rsync -e "/usr/bin/ssh" --compress --stats --bwlimit=2000 -rlDHS $SUSER@$SHOST:$SDIR
$LDIR
echo 'finished rsync, grabbing database'
WHOST=`cat $LDIR/wp-config.php | grep DB_HOST | cut -d \' -f 4`; # get the DB details
WNAME=`cat $LDIR/wp-config.php | grep DB_NAME | cut -d \' -f 4`;
WUSER=`cat $LDIR/wp-config.php | grep DB_USER | cut -d \' -f 4`;
WPASS=`cat $LDIR/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`;
ssh $SUSER@$SHOST "mysqldump -q -u $WUSER -h $WHOST -p$WPASS $WNAME | gzip -9 > backup.
sql.gz"
scp $SUSER@$SHOST:./backup.sql.gz . # copy all the files to backup server
ssh $SUSER@$SHOST rm ./backup.sql.gz # delete files on db server
gunzip -d backup.sql.gz # unzip it
mysql -u root -e "CREATE DATABASE IF NOT EXISTS $WNAME" # create the database locally
mysql -u root -e "GRANT ALL PRIVILEGES ON $WNAME.* To 'wp'@'localhost'"
mysql -u wp -pwp $WNAME < backup.sql # pull in the DB dump
sed -i "/DB_HOST/s/'[^']*'/'localhost'/2" wp-config.php # change wp-config.php values
sed -i "/DB_USER/s/'[^']*'/'wp'/2" wp-config.php
sed -i "/DB_PASSWORD/s/'[^']*'/'wp'/2" wp-config.php