diff --git a/.DS_Store b/.DS_Store index 6441accd..fdc0c957 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/workflows/audio_backup.yml b/.github/workflows/audio_backup.yml new file mode 100644 index 00000000..a866a313 --- /dev/null +++ b/.github/workflows/audio_backup.yml @@ -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 diff --git a/.gitignore b/.gitignore index a2546560..c017815e 100644 --- a/.gitignore +++ b/.gitignore @@ -134,4 +134,8 @@ dist .pnp.* # Cypress -./cypress/ \ No newline at end of file +./cypress/ + +# Backup directories +./igbo_api_db +./aws_pronunciations diff --git a/scripts/aws_sync.sh b/scripts/aws_sync.sh new file mode 100755 index 00000000..3230ba46 --- /dev/null +++ b/scripts/aws_sync.sh @@ -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