acyang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 使用S3 儲存的幾個方式 # 1. Mount S3 as Network Drive ## 用 Goofys 掛載 S3 儲存 ### 安裝 ``` # 下載最新版的 goofys 二進位執行檔 wget https://github.com/kahing/goofys/releases/latest/download/goofys # 設定執行權限 chmod +x goofys mv goofys ~/bin ``` ### 認證 ``` # 建立 ~/.aws 目錄 mkdir ~/.aws # 建立 ~/.aws/credentials 設定檔 touch ~/.aws/credentials ``` 在 ~/.aws/credentials 設定檔中填入 S3 的 access key 與 secret key,若有多組金鑰則可放在不同的 profile 設定區塊之中。 ``` [default] aws_access_key_id = xxxxxxxxxxxxxxxx aws_secret_access_key = asdsdffghfhgjghkyujkjlkj;kl;t6ytgfhfgbqwev [profile-1] aws_access_key_id = yyyyyyyyyyyyyyyyy aws_secret_access_key = 123dtyuk,hxcbtrasdxcvghtyusadfyvhortiopnv [profile-2] aws_access_key_id = zzzzzzzzzzzzzzzzzzzzzz aws_secret_access_key = piudvogfjrtynzxbchzxgftyqwerfoffubjvdfohbuir ``` 金鑰與節點可以到TWCC查看 登入TWCC主頁=>雲端物件儲存=>第三方軟體下載 點選眼睛圖示後複製 ![](https://cos.twcc.ai/SYS-MANUAL/uploads/upload_73f7e9ced6b191d3d659aa0e61d27c86.png) ### 掛載 `~/bin/goofys --profile=profile-1 --endpoint=https://s3.twcc.ai <S3_bucket_name> <local_folder_name>` ### 卸載 `fusermount -u <local_folder_name>` [](https://i.imgur.com/R81AsFr.png) # 2. Use Amazon S3 User Interface Tools ## aws cli v2 ### 安裝 [安裝或更新最新版本的AWS CLI](https://docs.aws.amazon.com/zh_tw/cli/latest/userguide/getting-started-install.html) ### 組態與認證 [組態與憑證檔案設定](https://docs.aws.amazon.com/zh_tw/cli/latest/userguide/cli-configure-files.html) 使用`aws configure`進行設定,預設路徑存放於主目錄下的`.aws`資料夾。 Unix 系統中是使用 $HOME 或 ~ (波狀符號) 來參考,Windows 中是使用環境變數 %UserProfile% 來參考。 不敏感的資訊放在config檔案,敏感的資訊放在credentials檔案。 ~/.aws/config ``` [default] region= output=json [profile1] region= output=json [profile2] region= output=json ``` ~/.aws/credentials ``` [default] aws_access_key_id=xxxxxxxxxxx aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx [profile1] aws_access_key_id=xxxxxxxxxxx aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx [profile2] aws_access_key_id=xxxxxxxxxxx aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx ``` 也可將`AWS_CONFIG_FILE`環境變數設為其他本機路徑,以指定 config 檔案的非預設位置。 ### 使用高階 (s3) 命令 [aws s3](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/index.html) #### 建立儲存貯體(在TWCC未成功) `aws s3 mb s3://bucket-name` #### 刪除儲存貯體(在TWCC未成功) 移除 s3://bucket-name 儲存貯體 `aws s3 rb s3://bucket-name` 若要移除不是空的儲存貯體,您需要包含 --force 選項。 `aws s3 rb s3://bucket-name --force` #### 列出儲存貯體和物件 列出所有 Amazon S3 儲存貯體。 `aws s3 ls` 列出儲存貯體中的所有物件 `aws s3 ls s3://bucket-name` #### 刪除物件 `aws s3 rm s3://bucket-name/example/filename.txt` #### 複製物件 s3://bucket-name/example 的物件複製到 s3://my-bucket/ `aws s3 cp s3://bucket-name/example s3://my-bucket/` 將本機檔案從目前的工作目錄複製至 Amazon S3 儲存貯體。 `aws s3 cp filename.txt s3://bucket-name` 從 Amazon S3 儲存貯體複製至目前的工作目錄 `aws s3 cp s3://bucket-name/filename.txt ./` #### 移動物件 物件從 s3://bucket-name/example 移動至 s3://my-bucket/ `aws s3 mv s3://bucket-name/example s3://my-bucket/` 將本機檔案從目前的工作目錄移動至 Amazon S3 儲存貯體。 `aws s3 mv filename.txt s3://bucket-name` 從 Amazon S3 儲存貯體移動至目前的工作目錄 `aws s3 mv s3://bucket-name/filename.txt ./` #### 同步物件 將名為 my-bucket 的儲存貯體中名為 path 的 Amazon S3 前綴內容與目前的工作目錄進行同步。 `aws s3 sync . s3://my-bucket/path` ### 使用 API 層級 (s3api) 命令 [aws s3api](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/index.html) #### 建立儲存貯體 The following create-bucket example creates a bucket named my-bucket ``` aws s3api create-bucket --bucket my-bucket ``` #### 刪除儲存貯體 The following command deletes a bucket named my-bucket: ``` aws s3api delete-bucket --bucket my-bucket ``` ## winscp 開啟後跳出站台設定,點選新增站台,在檔案協定選擇Amazon S3。 主機名稱 存取金鑰 保密存取金鑰 可以參考[TWCC-雲端物件連線資訊](https://man.twcc.ai/@preview-twccdocs/doc-cos-main-zh/https%3A%2F%2Fman.twcc.ai%2F%40preview-twccdocs%2Fguide-cos-connect-info-zh)取得 ![](https://cos.twcc.ai/SYS-MANUAL/uploads/upload_b5e8373aed3a71e267267db866ac4ecd.png) 若有設定aws cli credentials的話,可以勾選"從AWS CLI組態讀取認證資訊" 登入後就跟平常使用winscp一樣 ![](https://cos.twcc.ai/SYS-MANUAL/uploads/upload_d92df8c4705031016fec3945a88abaac.png) ## S3 Browser 可參考[TWCC-使用第三方軟體管理檔案-S3 Browser](https://man.twcc.ai/@preview-twccdocs/doc-cos-main-zh/%2F%40preview-twccdocs%2Fguide-cos-s3browser-zh) # 3. Use AWS SDK for Python (Boto3) ## Boto Boto 是一種 Python AWS SDK 套件,提供連接 AWS 的介面 (包含 Amazon S3) [Boto3](https://aws.amazon.com/tw/sdk-for-python/) ### 安裝 `pip install boto3` ### 認證 和aws cli共用認證 ### download files(text mode) 把遠端bucket內的檔案下載到本地的檔案系統(以text mode開啟) ``` s3 = boto3.client('s3') with open('FILE_NAME', 'w') as f: s3.download_file('BUCKET_NAME', 'OBJECT_NAME', f) ``` 考慮到Taiwania3上都有`/scratch`資料夾,在計算過程中,將檔案下載到`/scratch`是一個好選擇。 ``` with open('/scratch/local_file.txt', 'w') as f: s3.download_file('my_BUCKET', 'local_file', f) ``` ### download files(binary mode) 把遠端bucket內的檔案下載到本地的檔案系統(以binary mode開啟) ``` s3 = boto3.client('s3') with open('FILE_NAME', 'wb') as f: s3.download_fileobj('BUCKET_NAME', 'OBJECT_NAME', f) ``` ## 應用情境 利用aws cli v2 將HFS資料搬移到S3 ``` 02:19:32 p00acy00@lgn303:nerf$ aws --profile=GOV110172-public --endpoint-url=https://s3.twcc.ai s3 sync old_data/ s3://olddata/ ``` 再用gooyfs掛載 S3 儲存 ``` 02:19:32 p00acy00@lgn303:nerf$ ~/bin/goofys --profile=GOV110172-public --endpoint=https://s3.twcc.ai olddata ~/s3_folder/ 02:20:05 p00acy00@lgn303:nerf$ ls ~/s3_folder/ ... ``` 使用diff比對HFS資料以及S3資料 ``` 02:23:06 p00acy00@lgn303:p00acy00$ diff -qr nerf/old_data/ ~/s3_folder/ | sort ``` 比對無誤後使用fusermount卸載 S3 儲存 ``` 04:15:12 p00acy00@lgn303:p00acy00$ fusermount -u ~/s3_folder/ 08:30:55 p00acy00@lgn303:p00acy00$ ls ``` 刪除HFS儲存 ``` 08:31:38 p00acy00@lgn303:nerf$ rm -rf old_data/ ``` ## 參考資料 [Linux 使用 diff 指令比較兩個目錄的檔案差異教學與範例](https://officeguide.cc/linux-diff-files-in-two-different-directories-tutorial-examples/) [Linux 使用 Goofys 掛載 S3 儲存空間教學與範例](https://officeguide.cc/linux-goofys-mount-s3-bucket-filey-system-tutorial-examples/) [Connecting to Amazon S3 service](https://winscp.net/eng/docs/guide_amazon_s3) [Connecting to an S3 Bucket using WinSCP](https://infra.engineer/aws/18-connecting-to-an-s3-bucket-using-winscp) sudo rsync -avzh --progress -e 'ssh -i .ssh/kp1570410003932.pem' /home ubuntu@103.124.75.59:/media/203.145.222.147/home

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully