Skip to content

Add support to diferential and log MSSQL backups#69

Closed
eduartua wants to merge 3 commits intomainfrom
mssql-diff-backups
Closed

Add support to diferential and log MSSQL backups#69
eduartua wants to merge 3 commits intomainfrom
mssql-diff-backups

Conversation

@eduartua
Copy link
Member

No description provided.

@eduartua eduartua self-assigned this Oct 20, 2025
mssql/README.md Outdated
- When you need the ability to restore to a specific point in time
- To keep the transaction log size manageable

**Note:** Not included in default configuration. Enable only if your database is in FULL recovery model and you need point-in-time recovery.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what this means. How do I know if my database is in "FULL recovery model" or what does that even mean? Why don't I need 'point-in-time recovery'? Why shouldn't we enable this by default?

S3_ENDPOINT="${S3_BUCKET}.s3.${S3_REGION}.amazonaws.com"
BACKUP_FILENAME="${DB_DATABASE}-$(date +%Y-%m-%d-%H-%M-%S).bak"
S3_URL="s3://${S3_ENDPOINT}/backups/${BACKUP_FILENAME}"
BACKUP_FILENAME="${DB_DATABASE}-full-$(date +%Y-%m-%d-%H-%M-%S).bak"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need %S second resolution in the file name if the most precise we'll ever be is by minute? It seems useless to have -00 in all backup file names.

Comment on lines +95 to +109
- name: MSSQL_SA_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .secretName }}
key: {{ .secretKey }}
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: {{ .secretName }}
key: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: {{ .secretName }}
key: AWS_SECRET_ACCESS_KEY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to statically set AWS credentials in secrets if you are running a bash script. Just put the following function in your bash script.

# Function to fetch AWS credentials from EC2 metadata service
fetch_aws_credentials() {
  local metadata_url="http://169.254.169.254/latest/meta-data/iam/security-credentials/"
  
  # 1. Get the IAM role name attached to the instance
  local role_name
  role_name=$(curl -s -f "$metadata_url")
  
  if [ -z "$role_name" ]; then
    echo "Error: Could not retrieve IAM role name. Is an IAM role attached?" >&2
    return 1
  fi
  
  echo "Fetching credentials for role: $role_name"

  # 2. Get the temporary credentials using the role name
  local credentials
  credentials=$(curl -s -f "$metadata_url$role_name")
  
  if [ -z "$credentials" ]; then
    echo "Error: Could not retrieve credentials for role $role_name." >&2
    return 1
  fi

  # 3. Parse the JSON response (using basic tools like grep/cut or jq if available)
  # Using grep and cut for portability (jq is better if installed: | jq -r .AccessKeyId)
  local access_key_id
  local secret_access_key
  local session_token
  
  access_key_id=$(echo "$credentials" | grep "AccessKeyId" | cut -d'"' -f4)
  secret_access_key=$(echo "$credentials" | grep "SecretAccessKey" | cut -d'"' -f4)
  session_token=$(echo "$credentials" | grep "Token" | cut -d'"' -f4) # Note: The key is "Token"

  if [ -z "$access_key_id" ] || [ -z "$secret_access_key" ] || [ -z "$session_token" ]; then
      echo "Error: Failed to parse credentials." >&2
      echo "Response was: $credentials" >&2
      return 1
  fi

  # 4. Export the credentials as environment variables
  export AWS_ACCESS_KEY_ID="$access_key_id"
  export AWS_SECRET_ACCESS_KEY="$secret_access_key"
  export AWS_SESSION_TOKEN="$session_token"
  
  echo "AWS credentials exported successfully."
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to put all of these bash scripts into a configmap if we have a custom docker image? Why not put them into the docker image so that they're properly source tracked and reusable?

@eduartua
Copy link
Member Author

eduartua commented Oct 21, 2025

@victortrac closing this one in favor of

@eduartua eduartua closed this Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants