Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "[START: $(date)]"
- # Our Config
- URL="staging.my-amazing-wp-site.com"
- DATE="$(date +%F-%H%M-%s)"
- OUTPUT_DIR="wp-static-${DATE}"
- FTP_URL="ftp.my-site.com"
- FTP_USER="username"
- FTP_PASS="password"
- TARGET_DIR="/public/static"
- # Archive site with wget
- wget --quiet --mirror -P "${OUTPUT_DIR}" -nH -np -p -k -E "${URL}"
- # Validate wget return code
- WGET_RETURN=$?
- if [ ${WGET_RETURN} -ne 0 ] && [ ${WGET_RETURN} -ne 8 ]; then
- case ${WGET_RETURN} in
- 1)
- echo "Error: Generic error code."
- ;;
- 2)
- echo "Error: Parse error—for instance, when parsing command-line options, the ‘.wgetrc’ or ‘.netrc’..."
- ;;
- 3)
- echo "Error: File I/O error."
- ;;
- 4)
- echo "Error: Network failure."
- ;;
- 5)
- echo "Error: SSL verification failure."
- ;;
- 6)
- echo "Error: Username/password authentication failure."
- ;;
- 7)
- echo "Error: Protocol errors."
- ;;
- esac
- echo "Failed to download archive of site: ${URL} - ${DATE}"
- exit 1
- elif [ ${WGET_RETURN} -eq 8 ]; then
- # This means a URL returned an error status, like 500 or 404.
- # Nothing to worry about usually.
- echo "Archive created successfully, with minor server errors: (nothing to worry about)"
- else
- echo "Archive created successfully:"
- fi
- tree "${OUTPUT_DIR}"
- # Deploy
- echo "Deploying ${OUTPUT_DIR} to ${FTP_URL}"
- echo "Username: ${FTP_USER}"
- echo "Password: ${FTP_PASS}"
- ncftpput -R -u "${FTP_USER}" -p "${FTP_PASS}" "${FTP_URL}" "${TARGET_DIR}" ./"${OUTPUT_DIR}"/* > ./deploy-"${DATE}".log 2>&1
- FTP_RETURN=$?
- echo "[FINISH: $(date)]"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement