-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2644 from GSA-TTS/main
- Loading branch information
Showing
18 changed files
with
160 additions
and
2,605 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
--- | ||
name: Perform Media and Database Backups | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
backup-media: | ||
if: ${{ inputs.environment == 'dev' }} | ||
name: Perform Media Backups | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
env: | ||
space: ${{ inputs.environment }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Unbind the private s3 bucket | ||
uses: cloud-gov/cg-cli-tools@main | ||
with: | ||
cf_username: ${{ secrets.CF_USERNAME }} | ||
cf_password: ${{ secrets.CF_PASSWORD }} | ||
cf_org: gsa-tts-oros-fac | ||
cf_space: ${{ env.space }} | ||
command: cf unbind-service gsa-fac fac-private-s3 | ||
|
||
- name: Rebind the private s3 bucket with backups bucket as an additional instance | ||
uses: cloud-gov/cg-cli-tools@main | ||
with: | ||
cf_username: ${{ secrets.CF_USERNAME }} | ||
cf_password: ${{ secrets.CF_PASSWORD }} | ||
cf_org: gsa-tts-oros-fac | ||
cf_space: ${{ env.space }} | ||
command: | | ||
cf bind-service gsa-fac fac-private-s3 -c '{"additional_instances": ["backups"]}' | ||
- name: Restart the app | ||
uses: cloud-gov/cg-cli-tools@main | ||
with: | ||
cf_username: ${{ secrets.CF_USERNAME }} | ||
cf_password: ${{ secrets.CF_PASSWORD }} | ||
cf_org: gsa-tts-oros-fac | ||
cf_space: ${{ env.space }} | ||
command: cf restart gsa-fac | ||
|
||
- name: Backup media files | ||
uses: cloud-gov/cg-cli-tools@main | ||
with: | ||
cf_username: ${{ secrets.CF_USERNAME }} | ||
cf_password: ${{ secrets.CF_PASSWORD }} | ||
cf_org: gsa-tts-oros-fac | ||
cf_space: ${{ env.space }} | ||
command: cf run-task gsa-fac -k 2G -m 2G --name media_backup --command "./s3-sync.sh" | ||
|
||
backup-dev-database: | ||
if: ${{ inputs.environment == 'dev' }} | ||
name: Perform Dev Database Backups | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
env: | ||
space: ${{ inputs.environment }} | ||
steps: | ||
- name: Backup Dev Database | ||
uses: cloud-gov/cg-cli-tools@main | ||
with: | ||
cf_username: ${{ secrets.CF_USERNAME }} | ||
cf_password: ${{ secrets.CF_PASSWORD }} | ||
cf_org: gsa-tts-oros-fac | ||
cf_space: ${{ env.space }} | ||
command: cf run-task gsa-fac -k 2G -m 2G --name pg_backup --command "./backup_database.sh ${{ env.space }}" | ||
|
||
# backup-prod-database: | ||
# if: ${{ inputs.environment == 'production' }} | ||
# name: Perform Prod Database Backups | ||
# runs-on: ubuntu-latest | ||
# environment: ${{ inputs.environment }} | ||
# env: | ||
# space: ${{ inputs.environment }} | ||
# steps: | ||
# - name: Bind backup s3 bucket to prod app | ||
# uses: cloud-gov/cg-cli-tools@main | ||
# with: | ||
# cf_username: ${{ secrets.CF_USERNAME }} | ||
# cf_password: ${{ secrets.CF_PASSWORD }} | ||
# cf_org: gsa-tts-oros-fac | ||
# cf_space: ${{ env.space }} | ||
# command: cf bind-service gsa-fac backups -w | ||
|
||
# - name: Backup the database (Prod Only) | ||
# uses: cloud-gov/cg-cli-tools@main | ||
# with: | ||
# cf_username: ${{ secrets.CF_USERNAME }} | ||
# cf_password: ${{ secrets.CF_PASSWORD }} | ||
# cf_org: gsa-tts-oros-fac | ||
# cf_space: ${{ env.space }} | ||
# command: cf run-task gsa-fac -k 2G -m 2G --name pg_backup --command "./backup_database.sh ${{ env.space }}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# This requires: cf bind-service gsa-fac fac-private-s3 -c '{"additional_instances": ["backups"]}' | ||
|
||
# Grab AWS cli | ||
unset https_proxy | ||
curl -L "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | ||
unzip awscliv2.zip && rm awscliv2.zip | ||
./aws/install -i ~/usr -b ~/bin | ||
/home/vcap/app/bin/aws --version | ||
|
||
# Get the fac-private-s3 bucket | ||
export S3CREDS="$(echo $VCAP_SERVICES|jq -r '.s3')" | ||
export FACPRIVS3="$(echo $S3CREDS|jq '.[]|select(.name=="fac-private-s3")'|jq '.credentials')" | ||
export AWS_ACCESS_KEY_ID="$(echo "$FACPRIVS3"|jq -r '.access_key_id')" | ||
export AWS_SECRET_ACCESS_KEY="$(echo "$FACPRIVS3"|jq -r '.secret_access_key')" | ||
export FAC_MEDIA_BUCKET="$(echo "$FACPRIVS3"|jq -r '.bucket')" | ||
export AWS_DEFAULT_REGION='us-gov-west-1' | ||
|
||
# Get the backups bucket | ||
export FACBACKUPS="$(echo $S3CREDS|jq '.[]|select(.name=="backups")'|jq '.credentials')" | ||
export BACKUPS_BUCKET="$(echo "$FACBACKUPS"|jq -r '.bucket')" | ||
|
||
date=$(date +%Y%m%d%H%M) | ||
|
||
# Grab the s3 tar binary | ||
curl -L "https://github.com/awslabs/amazon-s3-tar-tool/releases/download/v1.0.14/s3tar-linux-amd64.zip" -o "s3tar-linux-amd64.zip" | ||
unzip s3tar-linux-amd64.zip && rm s3tar-linux-amd64.zip | ||
|
||
# Create a single tar in the source bucket | ||
./s3tar-linux-amd64 --region $AWS_DEFAULT_REGION -cvf s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/archive.tar s3://${FAC_MEDIA_BUCKET} --storage-class INTELLIGENT_TIERING | ||
|
||
# List contents of source bucket | ||
/home/vcap/app/bin/aws s3 ls s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/ | ||
|
||
# Move the tar to the backups bucket | ||
/home/vcap/app/bin/aws s3 sync s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/ s3://${BACKUPS_BUCKET}/mediabackups/$date/ --storage-class INTELLIGENT_TIERING | ||
# Share the Tar to dest and extract (without including the tar) | ||
#./s3tar-linux-amd64 --region $AWS_DEFAULT_REGION -cvf s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/archive.tar -C s3://${BACKUPS_BUCKET}/mediabackups/$date/ --storage-class INTELLIGENT_TIERING | ||
|
||
# List contents of destination bucket | ||
/home/vcap/app/bin/aws s3 ls s3://${BACKUPS_BUCKET}/mediabackups/$date/ | ||
|
||
# Cleanup the source bucket so older backups don't get added to the tar | ||
/home/vcap/app/bin/aws s3 rm s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/archive.tar | ||
/home/vcap/app/bin/aws s3 rm s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/ | ||
/home/vcap/app/bin/aws s3 rm s3://${FAC_MEDIA_BUCKET}/mediabackups/ | ||
|
||
# List contents of source bucket to ensure everything was deleted properly | ||
/home/vcap/app/bin/aws s3 ls s3://${FAC_MEDIA_BUCKET}/mediabackups/$date/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.