Skip to content

aspiredu/crunchy-backups

Repository files navigation

A Python script used to transfer backups stored on the CrunchyBridge S3 Bucket to AspirEDU's S3 Bucket.

Contributing

Install dependencies

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Install pre-commit hooks:

pre-commit install

Updating Python dependencies

source venv/bin/activate
pip-compile --upgrade

Re-running a failed backup

Occasionally backups will fail. To re-run them, you can start a [Adhoc] Start Script via Terraform GitHub Action by clicking on "Run Workflow".

There are three inputs you'll need to populate:

  1. Branch (main is what you should use unless you know different)
  2. Database (the database that failed)
  3. Working dir (us-east for most databases, aspiredu-au needs au)
  4. Backup target (the date in the format YYYYMMDD)

Testing Locally

  1. Ensure the Terraform CLI is installed. The following command should output the currently installed version of the Terraform CLI:
terraform --version
  1. Create a new .env.terraform file with the following content:
export TF_VAR_CRUNCHY_TEAM_ID=CRUNCHY_TEAM_ID
export TF_VAR_CRUNCHY_API_KEY=CRUNCHY_API_KEY
export TF_VAR_ASPIRE_AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
export TF_VAR_ASPIRE_AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY
export TF_VAR_GIT_PAT=GIT_PERSONAL_ACCESS_TOKEN
export TF_VAR_ASPIRE_CLUSTER=ASPIRE_CLUSTER_TO_RUN_FOR
export AWS_ACCESS_KEY_ID="$TF_VAR_ASPIRE_AWS_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="$TF_VAR_ASPIRE_AWS_SECRET_ACCESS_KEY"
  1. Load the environment variables from the file with the following command:
source .env.terraform
  1. Navigate to the directory in this repository for the region to use for testing (likely us-east).

  2. Initialize Terraform with the following command:

terraform init -backend-config="key=$TF_VAR_ASPIRE_CLUSTER/terraform.tfstate"
  1. (Optional but recommended) Verify the actions Terraform will take when applied with the following command:
terraform plan
  1. Run the following command to apply the changes from Step 6 and provision the specified resources from AWS:
terraform apply
  1. The EC2 Instance will be provisioned by Terraform along with the supporting Volume for storage. The state can be viewed through the AWS Web Portal. Connect to the EC2 Instance via SSH (instructions can be found on the AWS Web Portal).

Note: Accessing the instance via SSH requires the .pem private key file corresponding to the AWS Key Pair used by Terraform when provisioning the EC2 instance.

  1. Verify the volume was mounted at the correct point in the file structure, verify the file structure itself is as expected, and check that the Python script is running. Here are a few useful commands:

View Attached Drives with Filesystem and Mount Points

lsblk -f

View Running Processes

htop

View Start-Up Script Sent to Userdata

curl http://169.254.169.254/latest/user-data

The logs for the Start-Up Script can be found at /var/log/cloud-init-output.log.

Process overview

This process uses GitHub actions and Terraform to control AWS EC2 instances that copy our backups between S3 buckets.

graph TD
    A[Start Script via Terraform tf-deploy.yml GH action] --> B{Is first or third Sat}
    B -->|no| C[Done]
    B -->|yes| D[Start Terraform]
    D --> E[Spin up EC2 and EBS instances]
    E --> F[Copy via crunchy_copy.py]
    F --> G[Ping deadman's snitch]
    G -->|Send GitHub API request| H[Trigger tf-destroy.yml GH action]
    H --> I[Terraform tear down of EC2 and EBS instances]
    I --> C
Loading

Restore process

See our (Database Developer docs)[https://github.com/aspiredu/aspiredu/blob/main/docs/docs/dev/database.rst]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published