diff --git a/sk1/backup.sh b/sk1/backup.sh index 83866f2..86fe8d2 100644 --- a/sk1/backup.sh +++ b/sk1/backup.sh @@ -1,22 +1,3 @@ -#!/usr/bin/env bash -# backup.sh — Create a manual RDS snapshot for Notes App -# Usage: source .env && ./backup.sh -set -euo pipefail +#!/bin/bash -: "${AWS_REGION:?Set AWS_REGION in .env}" - -SNAPSHOT_ID="notes-app-manual-$(date +%Y%m%d-%H%M%S)" - -echo "Creating RDS snapshot: ${SNAPSHOT_ID}..." -aws rds create-db-snapshot \ - --db-instance-identifier notes-app-db \ - --db-snapshot-identifier "$SNAPSHOT_ID" \ - --region "$AWS_REGION" \ - --output none - -echo "Waiting for snapshot to complete..." -aws rds wait db-snapshot-completed \ - --db-snapshot-identifier "$SNAPSHOT_ID" \ - --region "$AWS_REGION" - -echo "✅ Backup complete: ${SNAPSHOT_ID}" +docker exec app_db pg_dump -U notesuser notesdb > backup.sql diff --git a/sk1/create-vm.sh b/sk1/create-vm.sh new file mode 100644 index 0000000..ee96ea7 --- /dev/null +++ b/sk1/create-vm.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# VARIABLES +KEY_NAME="my-key" +SECURITY_GROUP="notes-app-sg" +INSTANCE_NAME="notes-app-vm" +AMI_ID="ami-0e872aee57663ae2d" +INSTANCE_TYPE="t2.micro" +REGION="eu-central-1" + +# CREATE SECURITY GROUP +aws ec2 create-security-group \ + --group-name $SECURITY_GROUP \ + --description "Security group for Notes App" \ + --region $REGION + +# OPEN PORTS +aws ec2 authorize-security-group-ingress \ + --group-name $SECURITY_GROUP \ + --protocol tcp \ + --port 22 \ + --cidr 0.0.0.0/0 \ + --region $REGION + +aws ec2 authorize-security-group-ingress \ + --group-name $SECURITY_GROUP \ + --protocol tcp \ + --port 80 \ + --cidr 0.0.0.0/0 \ + --region $REGION + +aws ec2 authorize-security-group-ingress \ + --group-name $SECURITY_GROUP \ + --protocol tcp \ + --port 443 \ + --cidr 0.0.0.0/0 \ + --region $REGION + +aws ec2 authorize-security-group-ingress \ + --group-name $SECURITY_GROUP \ + --protocol tcp \ + --port 8080 \ + --cidr 0.0.0.0/0 \ + --region $REGION + +aws ec2 authorize-security-group-ingress \ + --group-name $SECURITY_GROUP \ + --protocol tcp \ + --port 8081 \ + --cidr 0.0.0.0/0 \ + --region $REGION + +# CREATE INSTANCE +aws ec2 run-instances \ + --image-id $AMI_ID \ + --count 1 \ + --instance-type $INSTANCE_TYPE \ + --key-name $KEY_NAME \ + --security-groups $SECURITY_GROUP \ + --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$INSTANCE_NAME}]" \ + --region $REGION \ No newline at end of file diff --git a/sk1/deploy.sh b/sk1/deploy.sh new file mode 100644 index 0000000..aff6ac4 --- /dev/null +++ b/sk1/deploy.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +sudo apt update + +sudo apt install docker.io docker-compose nginx certbot python3-certbot-nginx -y + +sudo systemctl enable docker +sudo systemctl start docker + +docker-compose up -d --build \ No newline at end of file diff --git a/sk1/destroy.sh b/sk1/destroy.sh new file mode 100644 index 0000000..354ca1f --- /dev/null +++ b/sk1/destroy.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +docker-compose down -v \ No newline at end of file