SHARE
TWEET

Untitled

a guest Apr 1st, 2019 138 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # 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
  3.  
  4. SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
  5. cd $SCRIPTPATH
  6.  
  7. site_id=$1
  8. virtual_host=$2
  9. ftp_host=$3
  10. ftp_port=$4
  11. ftp_user=$5
  12. ftp_pass=$6
  13. if [ -z "${7}" ]
  14. then
  15.     ftp_web_directory="/"
  16. else
  17.     ftp_web_directory=${7}
  18. fi
  19. if [ -z "${8}" ]
  20. then
  21.     ftp_web_directory_depth="0"
  22. else
  23.     ftp_web_directory_depth=${8}
  24. fi
  25. if [ -z "${9}" ]
  26. then
  27.     db_only="no"
  28. else
  29.     db_only=${9}
  30. fi
  31. if [ -z "${10}" ]
  32. then
  33.     remove_ezwp_temp="yes"
  34. else
  35.     remove_ezwp_temp=${10}
  36. fi
  37.  
  38. shopt -s extglob
  39. ftp_host_trimmed="${ftp_host##*( )}"
  40. ftp_host_trimmed="${ftp_host_trimmed%%*( )}"
  41. shopt -u extglob
  42.  
  43. ezwp_mysql_host="ezdockwp-rds-main.cdob06sdskjd.us-east-1.rds.amazonaws.com"
  44. ezwp_mysql_dbname=$(echo $virtual_host | tr . _)
  45. ezwp_mysql_user="root"
  46. ezwp_mysql_password="dis-be-an-ultra-default-root-password"
  47.  
  48. # https://github.com/ifsnop/mysqldump-php
  49. ncftp -u "'"$ftp_user"'" -p "'"$ftp_pass"'" $ftp_host_trimmed <<END
  50. cd $ftp_web_directory
  51. mkdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup
  52. mkdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php
  53. cd ${ftp_web_directory}wp-content/plugins/ezwp-db-backup
  54. 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
  55. 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
  56. mkdir mysqldump-php
  57. cd mysqldump-php
  58. mkdir src
  59. mkdir unit-tests
  60. cd ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php
  61. put -R /efs/ezdockefs-1/scripts/mysqldump-php/*
  62. END
  63.  
  64. right_now_millis=`echo $(($(date +%s%N)/1000000))`
  65. # curl -H 'User-Agent: Ezoic' -L $virtual_host/ezwp-temp/ez-db-dump.php?ezcb=${right_now_millis}
  66. curl -H 'User-Agent: Ezoic' -L $virtual_host/wp-content/plugins/ezwp-db-backup/ezwp-db-backup.php?ezcb=${right_now_millis}
  67.  
  68. if [[ "$remove_ezwp_temp" == "yes" ]]
  69. then
  70.     ncftp -u "'"$ftp_user"'" -p "'"$ftp_pass"'" $ftp_host_trimmed <<END
  71.     cd $ftp_web_directory
  72.     get -z ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/db-dump.sql $SCRIPTPATH/temp/$site_id.sql
  73.     delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src/Ifsnop/Mysqldump/*
  74.     rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src/Ifsnop/Mysqldump
  75.     rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src/Ifsnop
  76.     rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/src
  77.     delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/unit-tests/MysqldumpTest.php
  78.     rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/unit-tests
  79.     delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php/*
  80.     rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/mysqldump-php
  81.     delete ${ftp_web_directory}wp-content/plugins/ezwp-db-backup/*
  82.     rmdir ${ftp_web_directory}wp-content/plugins/ezwp-db-backup
  83. END
  84. fi
  85.  
  86. # mv $SCRIPTPATH/ez-db-dump.sql $SCRIPTPATH/temp/$site_id.sql
  87. echo "importing db to staging"
  88. mysql -u $ezwp_mysql_user -p"$ezwp_mysql_password" -h $ezwp_mysql_host $ezwp_mysql_dbname < $SCRIPTPATH/temp/$site_id.sql
  89.  
  90. if [[ "$db_only" == "yes" ]]
  91. then
  92.     exit 0
  93. fi
  94.  
  95. # echo "deleting downloaded db dump file"
  96. # rm -rf $SCRIPTPATH/temp/$site_id.sql
  97.  
  98. echo "resetting existing staging web folder (if it exists)"
  99. # rm -rf /efs/ezdockefs-1/$site_id/files
  100. mkdir -p /efs/ezdockefs-1/${site_id}_${right_now_millis}
  101. mv /efs/ezdockefs-1/$site_id /efs/ezdockefs-1/${site_id}_${right_now_millis}
  102.  
  103. mkdir -p /efs/ezdockefs-1/$site_id/files
  104. chown 33:33 /efs/ezdockefs-1/$site_id/files
  105.  
  106. echo "copying original site's web folder"
  107. cd /efs/ezdockefs-1/$site_id/files
  108. 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
  109.  
  110. echo "adjusting the folder paths on staging"
  111. shopt -s dotglob
  112. mv /efs/ezdockefs-1/$site_id/files${ftp_web_directory}* /efs/ezdockefs-1/$site_id/files
  113. shopt -u dotglob
  114. rmdir /efs/ezdockefs-1/$site_id/files${ftp_web_directory}
  115.  
  116. rm -rf /efs/ezdockefs-1/$site_id/files/ezwp.txt
  117. echo "hosted by ezoic" > /efs/ezdockefs-1/$site_id/files/ezwp.txt
  118.  
  119. echo "adding reverse proxy check, to prevent redirect loops"
  120. rm -rf /efs/ezdockefs-1/$site_id/files/wp-config-backup.php
  121. cp /efs/ezdockefs-1/$site_id/files/wp-config.php /efs/ezdockefs-1/$site_id/files/wp-config-backup.php
  122. 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
  123.  
  124. echo "chown-ing all the transfered files"
  125. shopt -s dotglob
  126. chown -R 33:33 /efs/ezdockefs-1/$site_id/files/*
  127. chown -R 33:33 /efs/ezdockefs-1/$site_id/files/.*
  128. shopt -u dotglob
  129.  
  130. if [ -e /efs/ezdockefs-1/$site_id/files/.htaccess ]
  131. then
  132.     cp /efs/ezdockefs-1/$site_id/files/.htaccess /efs/ezdockefs-1/$site_id/files/.htaccess_orig
  133.     cp /efs/ezdockefs-1/custom_containers/htaccess_default_wp /efs/ezdockefs-1/$site_id/files/.htaccess
  134.     chown 33:33 /efs/ezdockefs-1/$site_id/files/.htaccess
  135. fi
  136.  
  137. # echo "fixing wp_options"
  138. # 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}'"
  139.  
  140. echo "restarting the container"
  141. 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}'"
  142.  
  143. echo "great success"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top