#!/bin/bash # Install the required packages # # -------------------------------------------------------------- apt update && apt install curl unzip zip mariadb-client -y curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install # ------------------------------------------------------------------------------------------------------------------------- opt=$1 case $opt in mysql-backup) echo "Running mysql backup with s3..." export DATABASES=perchon export MYSQL_USER=perchona # execute the command now # # -------------------------------------------------------------------------------------------------------------- mysqldump -h $DB_HOST --single-transaction --quick --lock-tables=false --user=pantheon --password=$DB_PASSWORD \ pantheon --skip-lock-tables | gzip > "/tmp/lifeline-web-pantheon-$(date +%Y-%m-%dT%H_%M_%S).sql.gz" # ---------------------------------------------------------------------------------------------------------- # upload the same to s3 # # ----------------------------------------- # aws s3 cp /tmp/lifeline-web-pantheon-*.sql.gz s3://caresage-dev-ws/mysqlbackups/ # aws s3 ls s3://caresage-dev-ws/mysqlbackups/ # upload to bitbucket # # --------------------------------------- FILE=`ls /tmp/lifeline-web-pantheon-*.sql.gz` curl --request POST -F files=@"$FILE" --url 'https://api.bitbucket.org/2.0/repositories/connectamerica/lifeline-ecommerce/downloads' \ --header "Authorization: Bearer $TOKEN" ;; mysql-backup-bitbucket) echo "Running bmysql-backup-s3 with bitbucket ..." export DATABASES=perchona export MYSQL_USER=perchona ;; wp-data-backup) echo "Running wp-data-s3..." cd /usr/share/nginx/html/wp-content/ zip -r lifeline-web-static-data-$(date +%Y-%m-%dT%H_%M_%S).zip ./uploads && FILE=`ls lifeline-web-static-data-*.zip` curl --request POST -F files=@"$FILE" --url 'https://api.bitbucket.org/2.0/repositories/connectamerica/lifeline-ecommerce/downloads' \ --header "Authorization: Bearer $TOKEN" #aws s3 mv lifeline-web-static-data-*.zip s3://caresage-dev-ws/staticbackups/ #aws s3 ls s3://caresage-dev-ws/staticbackups/ ;; wp-data-bitbucket) echo "Running wp-data-bitbucket ..." ;; *) echo "common job shell script utility taking variables from env" echo "Usage: $0 {mysql-backup|mysql-backup-bitbucket|wp-data-backup}" echo " mysql-backup : Run MySQL backup utility and upload" echo " mysql-backup-bitbucket : Run MySQL backup utility and upload it to bitbucket." echo " wp-data-backup : Run web server backup utility and uplaod." echo " wp-data-bitbucket : Run web server backup utility and uplaod to bitbucket." ;; esac