Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # usage: migrate-wordpress-ftp.sh site_id virtual_host ftp_host ftp_port ftp_user ftp_pass ftp_web_directory ftp_web_directory_depth db_only remove_ezwp_temp
- SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
- cd $SCRIPTPATH
- site_id=$1
- virtual_host=$2
- ftp_host=$3
- ftp_port=$4
- ftp_user=$5
- ftp_pass=$6
- if [ -z "${7}" ]
- then
- ftp_web_directory="/"
- else
- ftp_web_directory=${7}
- fi
- if [ -z "${8}" ]
- then
- ftp_web_directory_depth="0"
- else
- ftp_web_directory_depth=${8}
- fi
- if [ -z "${9}" ]
- then
- db_only="no"
- else
- db_only=${9}
- fi
- if [ -z "${10}" ]
- then
- remove_ezwp_temp="yes"
- else
- remove_ezwp_temp=${10}
- fi
- shopt -s extglob
- ftp_host_trimmed="${ftp_host##*( )}"
- ftp_host_trimmed="${ftp_host_trimmed%%*( )}"
- shopt -u extglob
- ezwp_mysql_host="ezdockwp-rds-main.cdob06sdskjd.us-east-1.rds.amazonaws.com"
- ezwp_mysql_dbname=$(echo $virtual_host | tr . _)
- ezwp_mysql_user="root"
- ezwp_mysql_password="dis-be-an-ultra-default-root-password"
- # https://github.com/ifsnop/mysqldump-php
- ncftp -u "'"$ftp_user"'" -p "'"$ftp_pass"'" $ftp_host_trimmed <<END
- cd $ftp_web_directory
- mkdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup
- mkdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php
- cd ${ftp_web_directory}wp-content/plugins/ezwp-db-backup
- put -z /efs/ezdockefs-1/scripts/ezwp-db-backup/ezwp-db-backup.php ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/ezwp-db-backup.php
- put -z /efs/ezdockefs-1/scripts/ezwp-db-backup/ezwp-db-backup-nohup.php ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/ezwp-db-backup-nohup.php
- mkdir mysqldump-php
- cd mysqldump-php
- mkdir src
- mkdir unit-tests
- cd ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php
- put -R /efs/ezdockefs-1/scripts/mysqldump-php/*
- END
- right_now_millis=`echo $(($(date +%s%N)/1000000))`
- # curl -H 'User-Agent: Ezoic' -L $virtual_host/ezwp-temp/ez-db-dump.php?ezcb=${right_now_millis}
- curl -H 'User-Agent: Ezoic' -L $virtual_host/wp-content/plugins/ezwp-db-backup/ezwp-db-backup.php?ezcb=${right_now_millis}
- if [[ "$remove_ezwp_temp" == "yes" ]]
- then
- ncftp -u "'"$ftp_user"'" -p "'"$ftp_pass"'" $ftp_host_trimmed <<END
- cd $ftp_web_directory
- get -z ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/db-dump.sql $SCRIPTPATH/temp/$site_id.sql
- delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src/Ifsnop/Mysqldump/*
- rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src/Ifsnop/Mysqldump
- rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src/Ifsnop
- rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src
- delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/unit-tests/MysqldumpTest.php
- rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/unit-tests
- delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/*
- rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php
- delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/*
- rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup
- END
- fi
- # mv $SCRIPTPATH/ez-db-dump.sql $SCRIPTPATH/temp/$site_id.sql
- echo "importing db to staging"
- mysql -u $ezwp_mysql_user -p"$ezwp_mysql_password" -h $ezwp_mysql_host $ezwp_mysql_dbname < $SCRIPTPATH/temp/$site_id.sql
- if [[ "$db_only" == "yes" ]]
- then
- exit 0
- fi
- # echo "deleting downloaded db dump file"
- # rm -rf $SCRIPTPATH/temp/$site_id.sql
- echo "resetting existing staging web folder (if it exists)"
- # rm -rf /efs/ezdockefs-1/$site_id/files
- mkdir -p /efs/ezdockefs-1/${site_id}_${right_now_millis}
- mv /efs/ezdockefs-1/$site_id /efs/ezdockefs-1/${site_id}_${right_now_millis}
- mkdir -p /efs/ezdockefs-1/$site_id/files
- chown 33:33 /efs/ezdockefs-1/$site_id/files
- echo "copying original site's web folder"
- cd /efs/ezdockefs-1/$site_id/files
- wget -r -l inf -np -nH --cut-dirs=$ftp_web_directory_depth --user="'"$ftp_user"'" --password="'"$ftp_pass"'" ftp://$ftp_host_trimmed$ftp_web_directory
- echo "adjusting the folder paths on staging"
- shopt -s dotglob
- mv /efs/ezdockefs-1/$site_id/files${ftp_web_directory}* /efs/ezdockefs-1/$site_id/files
- shopt -u dotglob
- rmdir /efs/ezdockefs-1/$site_id/files${ftp_web_directory}
- rm -rf /efs/ezdockefs-1/$site_id/files/ezwp.txt
- echo "hosted by ezoic" > /efs/ezdockefs-1/$site_id/files/ezwp.txt
- echo "adding reverse proxy check, to prevent redirect loops"
- rm -rf /efs/ezdockefs-1/$site_id/files/wp-config-backup.php
- cp /efs/ezdockefs-1/$site_id/files/wp-config.php /efs/ezdockefs-1/$site_id/files/wp-config-backup.php
- echo "$(sed '/<?php/r /efs/ezdockefs-1/scripts/wp-reverse-proxy-check.php' /efs/ezdockefs-1/$site_id/files/wp-config.php)" > /efs/ezdockefs-1/$site_id/files/wp-config.php
- echo "chown-ing all the transfered files"
- shopt -s dotglob
- chown -R 33:33 /efs/ezdockefs-1/$site_id/files/*
- chown -R 33:33 /efs/ezdockefs-1/$site_id/files/.*
- shopt -u dotglob
- if [ -e /efs/ezdockefs-1/$site_id/files/.htaccess ]
- then
- cp /efs/ezdockefs-1/$site_id/files/.htaccess /efs/ezdockefs-1/$site_id/files/.htaccess_orig
- cp /efs/ezdockefs-1/custom_containers/htaccess_default_wp /efs/ezdockefs-1/$site_id/files/.htaccess
- chown 33:33 /efs/ezdockefs-1/$site_id/files/.htaccess
- fi
- # echo "fixing wp_options"
- # ssh -i /root/chef/ec2.pem centos@35.173.34.148 "sudo /bin/bash -c 'cd /root/chef; ruby /root/chef/fix-wp-options.rb --site_id ${site_id}'"
- echo "restarting the container"
- ssh -i /root/chef/ec2.pem centos@35.173.34.148 "sudo /bin/bash -c 'cd /root/chef; ruby /root/chef/restart-site-container.rb --site_id ${site_id}'"
- echo "great success"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement