Skip to content

Instantly share code, notes, and snippets.

@mikamboo
Last active February 16, 2020 09:03
Show Gist options
  • Select an option

  • Save mikamboo/26741a2879325b60b3ddb46c3f44634b to your computer and use it in GitHub Desktop.

Select an option

Save mikamboo/26741a2879325b60b3ddb46c3f44634b to your computer and use it in GitHub Desktop.
K8S : AWS S3 Backup Cron Jobs

K8S to S3 Backup

Sample cron job resources to backup a simple wordpresse installation.

Prerequists

  • A docker image including ASW-CLI
  • AWS Credentials to access your AWS S3 bucket

Backup jobs

Job 1 : worpress

  • Zip the www installation directory
  • Sent it to S3 bucket

Job 2 : mysql

  • Create sqldump of target database
  • Sent it to S3 bucket

Docker images

  • For aws-cli :
FROM python:3.7-alpine

RUN pip3 --no-cache install awscli

ENTRYPOINT ["aws"]
apiVersion: v1
kind: Secret
metadata:
name: aws-secret
type: Opaque
data:
AWS_ACCESS_KEY_ID: XXXXXXXX # base64 encoded
AWS_SECRET_ACCESS_KEY: XXXXXXXXXXXXXXXX # base64 encoded
@mikamboo
Copy link
Author

mikamboo commented Feb 16, 2020

Dump command

read ROOT_PASSWORD
DUMP_FILE="$(date '+%Y-%m-%d')-wp.sql"
mysqldump --force --opt --user=root -p$ROOT_PASSWORD --databases wordpress > $DUMP_FILE

One line with compression

mysqldump -u root -p --databases wordpress | gzip > "$(date '+%Y-%m-%d')-wp.sql.gz"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment