AWS S3 မှာ Data Backup လုပ်ကြမယ်

Backing up personal data in the developer’s way

Myo Win Thein
4 min readApr 3, 2021

Intro

Cloud Storage ကို ဒီနေရာမှာ နှစ်မျိုးခွဲလိုက်မယ်၊ End user နဲ့ developer level ဆိုပြီး။ End user level ဆိုတာက Dropbox & Google Drive လိုကောင်တွေ။ File manage လုပ်ဖို့ dashboard လှလှလေးတစ်ခု ပေးထားမယ်၊ Features တွေလည်း အစုံပါမယ်။ Download link ထုတ်ချင်လား၊ collaborator ထည့်ချင်လား စသည် အကုန်ရှိတယ်။ Data တွေကို လူပေါင်းစုံ ဝိုင်းသုံးမယ့်အခြေအနေမျိုး၊ ခေါင်းရှုပ်မခံပဲ အလွယ်တကူပဲ backup လုပ်ချင်တဲ့ အခါမျိုးတွေမှာ သင့်တော်တယ်။ Offer storage နည်းတယ်၊ ဈေးလည်း အရမ်းများတယ်။

Dropbox Pricing

Developer level ဆိုတာက AWS S3 & GCP Cloud လိုဟာတွေ။ လူတိုင်းမသုံးတက်ဘူး၊ technical knowledge လိုတယ်။ Dashboard ပါပေမယ့် end users အတွက် optimize လုပ်ထားတာမျိုး မဟုတ်ဘူး။ လိုချင်ရင်တော့ Nextcloud လို file hosting ချိတ်ရမယ်။ အားသာချက်က Offer storage များတယ်ပြီး ဈေးအရမ်းသက်သာတယ်။ အခုရေးမှာက ဒီအမျိုးအစားကို AWS S3 ကို သုံးပြီး ရေးမှာပါ။

AWS S3 Pricing

Dropbox, Drive အစား ဘာလို့ S3 သုံးသင့်လဲ

ကိုယ့်စက်ထဲက personal data သီးသန့် backup လုပ်မယ်ဆို cloud storage နဲ့က CRUD သီးသန့်ပဲ relation ရှိမယ်။ ကိုယ့်စက်မှာတင် file access ရတာမို့ ဘယ်သူမှ dashboard မှာ သွားဖွင့်မကြည့်ဘူး။ File share ဖို့လိုရင်တောင် download link ထုတ်စရာမလိုပဲ third-party app တစ်ခုခုကနေ လှမ်းပို့လိုက်ရုံပါပဲ။ Collaborator ထည့်တာ၊ activity log ကြည့်တာ ဘာဆိုဘာမှ မလိုပါ။

ကိုယ်သာ technical knowledge ရှိမယ်ဆို S3 သုံးတာက Storage များများရပြီး ဈေးလည်းသက်သာပါတယ်။ ကိုယ်တိုင်လည်း အဲလိုသုံးနေတာ 30.7GB ကို တစ်လ $0.2 ဝန်းကျင်ပဲ အများဆုံးကုန်ပါတယ်။ Dropbox သာဆို $11.99 ကုန်မှာပါ။

အောက်မှာတော့ ကိုယ့်စက်ထဲက data တွေကို AWS S3 နဲ့ ဘယ်လို sync လုပ်မလဲ တစ်ဆင့်ခြင်းစီ ရေးပြပါမယ်။ AWS knowledge အသင့်အတင့်ရှိတယ်လို့ ယူဆလို့ တစ်ချို့အဆင့်တွေတော့ အသေးစိတ်မရေးတော့ပါဘူး။

Installation of the AWS CLI

Requirements

AWS account ရှိပြီး စက်ထဲမှာ awscli သွင်းပြီးပြီလို့ ယူဆလိုက်ပါမယ်။ S3 မှာ bucket တစ်ခု အရင်ဆောက်လိုက်ပါ။ မြန်မာနိုင်ငံအတွက်ဆို Asia Pacific (Mumbai) Region က အဆင်ပြေတယ်။

Configuration

Terminal မှာ အောက်က အတိုင်းရိုက်လိုက်ပါ။

Access Key ID နဲ့ Secret Access Key ကို လိုချင်ရင် “Console -> IAM -> Users -> Click User -> Security Credentials -> Access Keys -> Create access key”

Region Name ကို လိုချင်ရင် “Console -> S3 ->Bucket List -> AWS Region”

Syncing Data

အရင်ဆုံး backup မယ့် directory တွေကို စာရင်းလုပ်ပါ။ Linux နဲ့ macOS သမားတွေဆို Documents, Downloads, Music, Pictures, Videos နေရာတွေမှာ data အသိမ်းများပါတယ်။ ဒါကတော့ folder backup လုပ်တဲ့ command ပါ။

aws s3 sync ~/Documents s3://mwt-personal-data/Documents --delete --exclude "*._*" --exclude "*.DS_Store" --exclude "*.~lock*" --exclude "*Distros/*" --dryrun

တစ်ပိုင်းချင်းဆီ ပြန်ရှင်းပြပါမယ်။

  • aws s3 sync => awscli ရဲ့ s3 service ထဲက sync method
  • ~/Documents => စက်ထဲက backup လုပ်မယ့် folder
  • s3://mwt-personal-data/Documents => server ပေါ်က သိမ်းမည့် folder
  • — delete => စက်မှာဖျက်ရင် server မှာလည်း ဖျက်မယ်
  • — exclude “*._*” — exclude “*.DS_Store” — exclude “*.~lock*” => OS level က hidden files တွေ မပါအောင်လုပ်
  • — exclude “*Distros/*” => backup ထဲ မပါစေချင်တဲ့ folders တွေ
  • — dryrun => ဘာတွေတင်မလဲ list လုပ်ပြတာ၊ အဆင်ပြေတယ်ဆို ဖြုတ်ပြီး execute လုပ်ရုံ

နောက်ဆုံး Execute လုပ်လိုက်ရင် S3 ပေါ် အကုန်ရောက်သွားလိမ့်မယ်။ နောက်တစ်ကြိမ် execute ထပ်လုပ်ရင် file changes (create, update, delete) တွေပဲ ပါလိမ့်မယ်။ ပြဿနာတစ်ခုတော့ရှိတယ်၊ AWS မှာက Dropbox လို file name changes တွေကို detect မဖြစ်ဘူး။ ဆိုတော့ sync လုပ်တိုင်း server ပေါ်က အဟောင်းကိုဖျက်ပြီး အသစ်ပြန်တင်လိမ့်မယ်။

Check Uploaded File Size

aws s3 ls s3://mwt-personal-data --recursive --human-readable --summarize | tail -2

တစ်ပိုင်းချင်းဆီ ပြန်ရှင်းပြပါမယ်။

  • aws s3 ls => awscli ရဲ့ s3 service ထဲက ls method
  • s3://mwt-personal-data => server ပေါ်က s3 path
  • — recursive => sub-folders တွေပါ တွက်မယ်
  • — human-readable => file size ကို bytes အစား MB နဲ့ပြ
  • — summarize | tail -2 => File listing မပြခိုင်းဘူး၊ total count & size ပဲပြ

Delete Hidden Files

aws s3 rm s3://mwt-personal-data --recursive --exclude "*" --include "*._*" --include "*.DS_Store" --include "*.~lock*" --dryrun

တစ်ပိုင်းချင်းဆီ ပြန်ရှင်းပြပါမယ်။

  • aws s3 rm => awscli ရဲ့ s3 service ထဲက rm method
  • s3://mwt-personal-data => server ပေါ်က s3 path
  • — recursive => sub-folders တွေပါ တွက်မယ်
  • — exclude “*” => Whitelist ပုံစံနဲ့ ဖျက်မှာမို့၊ all files ignore လုပ်
  • — include “*._*” — include “*.DS_Store” — include “*.~lock*” => ဖျက်မယ့် file သီးသန့်ပြန်ရွေး
  • — dryrun => ဘာတွေဖျက်မလဲ list လုပ်ပြတာ၊ အဆင်ပြေတယ်ဆို ဖြုတ်ပြီး execute လုပ်ရုံ

Conclusion

အားလုံးပြီးသွားရင် commands တွေကို တစ်နေရာမှာသိမ်းပြီး တစ်လတစ်ကြိမ် backup ဖို့ reminder သာ ထည့်လိုက်ပါ။

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Myo Win Thein
Myo Win Thein

Written by Myo Win Thein

A developer sharing experiences with the world, one byte at a time.

Responses (1)

Write a response