Skip to content

Commit

Permalink
chore(ci): backup aws audio pronunciations
Browse files Browse the repository at this point in the history
  • Loading branch information
ijemmao committed Jun 23, 2021
1 parent a478788 commit 0ced24c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
42 changes: 42 additions & 0 deletions .github/workflows/audio_backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Backup AWS Audio Pronunciations

on:
schedule:
# Backs up AWS audio pronunciations every Sunday at 12:00 AM UTC
- cron: '0 0 * * 0'

on:
push

env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DROPBOX_TOKEN: ${{ secrets.DROPBOX_TOKEN }}
DIR: aws_pronunciations

jobs:
backup_aws:
name: Backup AWS
# https://github.com/actions/checkout/issues/440#issuecomment-778899551
runs-on: ubuntu-18.04

strategy:
matrix:
python-version: [3.8]

steps:
- name: Skipping steps
run: echo "Skipping steps"
# Skipping the following steps to prioritize using AWS S3 Glacier

# - name: Git checkout files and create aws db directory
# uses: actions/checkout@v2
# - name: Set up network configurations
# run: sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
# - name: Create temporary directory
# run: mkdir $DIR
# - name: Dump the AWS audio pronunciations
# run: aws s3 cp $AWS_S3_BUCKET ./$DIR --recursive --storage-class STANDARD --force-glacier-transfer
# - name: Upload to Dropbox
# run: ./scripts/aws_sync.sh $DROPBOX_TOKEN
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,8 @@ dist
.pnp.*

# Cypress
./cypress/
./cypress/

# Backup directories
./igbo_api_db
./aws_pronunciations
48 changes: 48 additions & 0 deletions scripts/aws_sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

#Get current date
NOW="$(date +'%m-%d-%Y_%H-%M')"

# Path to a temporary directory
DIR=aws_pronunciations

# Name of the database
DB_NAME=aws_igbo_api

# Name of the compressed file
FILE="${DB_NAME}_${NOW}.tar.gz"

function aws_compress
{

# Compress
tar -zcvf $FILE $DIR

# Remove the temporary database dump directory
rm -fr $DIR
}

aws_compress

readonly TOKEN=$1
readonly DIR=
BASENAME=$(basename $FILE)
if [ -f "$FILE" ]; then
# upload file to dropbox
CMD="upload $DIR/$BASENAME"
HTTP_CODE=$(curl -X POST -sL -w "%{http_code}" --output /dev/null https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer $TOKEN" \
--header "Dropbox-API-Arg: {\"path\": \"$DIR/$BASENAME\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @$FILE)
fi
echo $CMD
echo "Response code => $HTTP_CODE"

if [ $HTTP_CODE != "200" ]; then
echo "🔴 Backup failed"
exit 1
else
echo "✅ Backup successful"
exit 0
fi

0 comments on commit 0ced24c

Please sign in to comment.