Skip to content

Instantly share code, notes, and snippets.

@felipefernandes
Created May 14, 2018 00:43
Show Gist options
  • Save felipefernandes/b989e27a2337df90b8a4837139f8ad36 to your computer and use it in GitHub Desktop.
Save felipefernandes/b989e27a2337df90b8a4837139f8ad36 to your computer and use it in GitHub Desktop.
Bash Script for WP Deployment (Continuous Delivery)
#!/bin/bash
#
# needs: zip, unzip, rsync, openssh-client
#
# it can be used to run under bitbucket-pipelines playbook
# if so, remove variables and switch them for environment variables with $ prefix
PROJECT_PATH = "/sites/my-website.com"
REMOTE_HOST = "[email protected]"
REMOTE_PATH = "/var/www/html/my-website.com"
# zip built project
zip -r /tmp/build-latest.zip PROJECT_PATH
# copy zip to remote tmp folder
rsync -avzh --progress /tmp/build-latest.zip -e ssh REMOTE_HOST:/tmp
# backup rotine
# zip stable version of project
ssh REMOTE_HOST 'cd /tmp && zip -r build-stable.zip ' + REMOTE_PATH
# update the version
# unpack zip in tmp folder
ssh REMOTE_HOST 'unzip /tmp/build-latest.zip /tmp'
# copy the updated content of wp-content, themes, plugins and uploads to the right place
ssh REMOTE_HOST 'cp /tmp/build-latest/wp-content/themes/* ' + REMOTE_PATH + '/wp-content/themes'
ssh REMOTE_HOST 'cp /tmp/build-latest/wp-content/plugins/* ' + REMOTE_PATH + '/wp-content/plugins'
ssh REMOTE_HOST 'cp /tmp/build-latest/wp-content/uploads/* ' + REMOTE_PATH + '/wp-content/uploads'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment