-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path35b001da.6d0e50f3.js
1 lines (1 loc) · 6.9 KB
/
35b001da.6d0e50f3.js
1
"use strict";(self.webpackChunkadminforth=self.webpackChunkadminforth||[]).push([[9417],{289:(e,n,a)=>{a.r(n),a.d(n,{assets:()=>c,contentTitle:()=>o,default:()=>d,frontMatter:()=>i,metadata:()=>t,toc:()=>l});var t=a(6792),s=a(4848),r=a(8453);const i={slug:"backup-database-to-aws-glacier",title:"Backup database to AWS Glacier",authors:"ivanb",tags:["aws","terraform"]},o=void 0,c={authorsImageUrls:[void 0]},l=[{value:"Pricing",id:"pricing",level:2}];function u(e){const n={a:"a",code:"code",h2:"h2",li:"li",p:"p",pre:"pre",ul:"ul",...(0,r.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.p,{children:"Every reliable system requires a backup strategy."}),"\n",(0,s.jsx)(n.p,{children:"If you have no own backup infrastructure, here can suggest a small docker container that will help you to backup your database to AWS Glacier."}),"\n",(0,s.jsxs)(n.p,{children:["As a base guide we will use a previous blog post about ",(0,s.jsx)(n.a,{href:"/blog/compose-ec2-deployment-github-actions",children:"deploying adminforth infrastructure"}),"."]}),"\n",(0,s.jsx)(n.p,{children:"First we need to allocate a new bucket in AWS S3 with modifying terraform configuration:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-hcl",metastring:'title="deploy/main.tf"',children:'resource "aws_s3_bucket" "backup_bucket" {\n bucket = "${local.app_name}-backups"\n}\n\nresource "aws_s3_bucket_lifecycle_configuration" "backup_bucket" {\n bucket = aws_s3_bucket.backup_bucket.bucket\n\n rule {\n id = "glacier-immediate"\n status = "Enabled"\n\n transition {\n days = 0\n storage_class = "GLACIER"\n }\n }\n}\n\nresource "aws_s3_bucket_server_side_encryption_configuration" "backup_bucket" {\n bucket = aws_s3_bucket.backup_bucket.bucket\n\n rule {\n apply_server_side_encryption_by_default {\n sse_algorithm = "AES256"\n }\n }\n}\n\nresource "aws_iam_user" "backup_user" {\n name = "${local.app_name}-backup-user"\n}\n\nresource "aws_iam_access_key" "backup_user_key" {\n user = aws_iam_user.backup_user.name\n}\n\nresource "aws_iam_user_policy" "backup_user_policy" {\n name = "${local.app_name}-backup-policy"\n user = aws_iam_user.backup_user.name\n\n policy = jsonencode({\n Version = "2012-10-17"\n Statement = [\n {\n Effect = "Allow"\n Action = [\n "s3:PutObject",\n "s3:GetObject",\n "s3:DeleteObject",\n "s3:ListBucket"\n ]\n Resource = [\n aws_s3_bucket.backup_bucket.arn,\n "${aws_s3_bucket.backup_bucket.arn}/*"\n ]\n }\n ]\n })\n}\n\n'})}),"\n",(0,s.jsx)(n.p,{children:"Also add a section to main.tf to output the new bucket name and credentials:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-hcl",metastring:'title="deploy/main.tf"',children:' "docker system prune -f",\n # "docker buildx prune -f --filter \'type!=exec.cachemount\'",\n "cd /home/ubuntu/app/deploy",\n//diff-add \n "echo \'AWS_BACKUP_ACCESS_KEY=${aws_iam_access_key.backup_user_key.id}\' >> .env.live",\n//diff-add\n "echo \'AWS_BACKUP_SECRET_KEY=${aws_iam_access_key.backup_user_key.secret}\' >> .env.live",\n//diff-add\n "echo \'AWS_BACKUP_BUCKET=${aws_s3_bucket.backup_bucket.id}\' >> .env.live",\n//diff-add\n "echo \'AWS_BACKUP_REGION=${local.aws_region}\' >> .env.live",\n\n "docker compose -p app -f compose.yml --env-file ./.env.live up --build -d --quiet-pull"\n ]\n'})}),"\n",(0,s.jsx)(n.p,{children:"Add new service into compose file:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-yaml",metastring:'title="deploy/compose.yml"',children:"\n database_glacierizer:\n image: devforth/docker-database-glacierizer:v1.7\n\n environment:\n - PROJECT_NAME=MYAPP\n # do backup every day at 00:00\n - CRON=0 0 * * * \n\n - DATABASE_TYPE=PostgreSQL\n - DATABASE_HOST=db\n - DATABASE_NAME=adminforth\n - DATABASE_USER=admin\n - DATABASE_PASSWORD=${VAULT_POSTGRES_PASSWORD}\n - GLACIER_EXPIRE_AFTER=90\n - GLACIER_STORAGE_CLASS=flexible\n - GLACIER_BUCKET_NAME=${AWS_BACKUP_BUCKET}\n\n - AWS_DEFAULT_REGION=${AWS_BACKUP_REGION}\n - AWS_ACCESS_KEY_ID=${AWS_BACKUP_ACCESS_KEY}\n - AWS_SECRET_ACCESS_KEY=${AWS_BACKUP_SECRET_KEY}\n"})}),"\n",(0,s.jsx)(n.h2,{id:"pricing",children:"Pricing"}),"\n",(0,s.jsx)(n.p,{children:"Just to give you row idea about pricing, here is a small calculation for case when you doing backup once per day (like in config)"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:"Compressed database backup has size of 50 MB always and not growing. (Compression is already done by glacierizer)"}),"\n",(0,s.jsx)(n.li,{children:"Cost of glacier every month will be ~$0.80 after first 3 month, and will stay same every next month."}),"\n",(0,s.jsx)(n.li,{children:"On first, second and third month cost will increase slowly from $0.00 to $0.80 per month."}),"\n"]})]})}function d(e={}){const{wrapper:n}={...(0,r.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(u,{...e})}):u(e)}},8453:(e,n,a)=>{a.d(n,{R:()=>i,x:()=>o});var t=a(6540);const s={},r=t.createContext(s);function i(e){const n=t.useContext(r);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:i(e.components),t.createElement(r.Provider,{value:n},e.children)}},6792:e=>{e.exports=JSON.parse('{"permalink":"/blog/backup-database-to-aws-glacier","source":"@site/blog/2024-12-11-backup/index.md","title":"Backup database to AWS Glacier","description":"Every reliable system requires a backup strategy.","date":"2024-12-11T00:00:00.000Z","tags":[{"inline":false,"label":"AWS","permalink":"/blog/tags/aws","description":"Amazon Web Services (AWS) is a cloud computing platform that provides a wide range of services for building and deploying applications."},{"inline":false,"label":"Terraform","permalink":"/blog/tags/terraform","description":"Terraform is an open-source infrastructure as code software tool created by HashiCorp that enables users to define and provision data center infrastructure using a declarative configuration language."}],"readingTime":1.86,"hasTruncateMarker":true,"authors":[{"name":"Ivan Borshchov","title":"Maintainer of AdminForth","url":"https://github.com/ivictbor","imageURL":"https://avatars.githubusercontent.com/u/1838656?v=4","key":"ivanb","page":null}],"frontMatter":{"slug":"backup-database-to-aws-glacier","title":"Backup database to AWS Glacier","authors":"ivanb","tags":["aws","terraform"]},"unlisted":false,"prevItem":{"title":"Why manual Release Notes and Versions are a chaos and how to fix it","permalink":"/blog/why-manual-release-notes-and-versions-are-a-chaos-and-how-to-fix-it"},"nextItem":{"title":"Deploy AdminForth to EC2 with terraform on CI","permalink":"/blog/compose-ec2-deployment-github-actions"}}')}}]);