Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #!/bin/bash
  2. echo "[START: $(date)]"
  3.  
  4. # Our Config
  5. URL="staging.my-amazing-wp-site.com"
  6. DATE="$(date +%F-%H%M-%s)"
  7. OUTPUT_DIR="wp-static-${DATE}"
  8. FTP_URL="ftp.my-site.com"
  9. FTP_USER="username"
  10. FTP_PASS="password"
  11. TARGET_DIR="/public/static"
  12.  
  13. # Archive site with wget
  14. wget --quiet --mirror -P "${OUTPUT_DIR}" -nH -np -p -k -E "${URL}"
  15.  
  16. # Validate wget return code
  17. WGET_RETURN=$?
  18. if [ ${WGET_RETURN} -ne 0 ] && [ ${WGET_RETURN} -ne 8 ]; then
  19. case ${WGET_RETURN} in
  20. 1)
  21. echo "Error: Generic error code."
  22. ;;
  23. 2)
  24. echo "Error: Parse error—for instance, when parsing command-line options, the ‘.wgetrc’ or ‘.netrc’..."
  25. ;;
  26. 3)
  27. echo "Error: File I/O error."
  28. ;;
  29. 4)
  30. echo "Error: Network failure."
  31. ;;
  32. 5)
  33. echo "Error: SSL verification failure."
  34. ;;
  35. 6)
  36. echo "Error: Username/password authentication failure."
  37. ;;
  38. 7)
  39. echo "Error: Protocol errors."
  40. ;;
  41. esac
  42. echo "Failed to download archive of site: ${URL} - ${DATE}"
  43. exit 1
  44. elif [ ${WGET_RETURN} -eq 8 ]; then
  45. # This means a URL returned an error status, like 500 or 404.
  46. # Nothing to worry about usually.
  47. echo "Archive created successfully, with minor server errors: (nothing to worry about)"
  48. else
  49. echo "Archive created successfully:"
  50. fi
  51. tree "${OUTPUT_DIR}"
  52.  
  53. # Deploy
  54. echo "Deploying ${OUTPUT_DIR} to ${FTP_URL}"
  55. echo "Username: ${FTP_USER}"
  56. echo "Password: ${FTP_PASS}"
  57. ncftpput -R -u "${FTP_USER}" -p "${FTP_PASS}" "${FTP_URL}" "${TARGET_DIR}" ./"${OUTPUT_DIR}"/* > ./deploy-"${DATE}".log 2>&1
  58. FTP_RETURN=$?
  59. echo "[FINISH: $(date)]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement