Google Bucket storage ගැන දන්න අයගෙන් හෙල්ප් එකක් ඔනේ.

DevOps_Boy

Active member
  • Jul 28, 2023
    238
    120
    43
    මචන් මට ඔනෙ linux server එකක තියෙන directories google bucket එකකට daily sync කරන්න. හැබැ්‍යි මට server එකට gcloud and gsutil වගේ tools install කරන්න බෑ. මම ගාව bucket එකට අදාල key.json එක තියෙනවා. මේක කරන්න ක්‍රමයක් තියේද? මම ගූගල් එකෙයි chat gpt එකෙයි බැලුව. bash script එකකින් කරන්න try කරා ඒත් හරි ගියේ නෑ. මේකට හරි solution එකක් ලැබුනේ නෑ තාම. මේක කරන්න Idea එකක් දෙන්නකො.
     

    gamerlk

    Well-known member
  • Dec 23, 2023
    4,799
    6,566
    113
    bash script එකකින් කරන්න try කරා ඒත් හරි ගියේ නෑ
    kothanda hira une?

    chatgpt gave this.

    Bash:
    #!/bin/bash
    
    # Set your Google Cloud Storage bucket name and local directory path
    BUCKET_NAME="your-bucket-name"
    LOCAL_DIRECTORY="/path/to/local/directory"
    
    # Set your Google Cloud Storage API endpoint
    API_ENDPOINT="https://storage.googleapis.com"
    
    # Check if the local directory exists
    if [ ! -d "$LOCAL_DIRECTORY" ]; then
        echo "Error: Local directory not found: $LOCAL_DIRECTORY"
        exit 1
    fi
    
    # Iterate through files in the local directory and upload them to the bucket
    for file in "$LOCAL_DIRECTORY"/*
    do
        if [ -f "$file" ]; then
            FILE_NAME=$(basename "$file")
            UPLOAD_URL="${API_ENDPOINT}/${BUCKET_NAME}/${FILE_NAME}"
    
            # Make a PUT request to upload the file
            curl -X PUT --upload-file "$file" "$UPLOAD_URL"
    
            # Check the HTTP status code
            if [ $? -eq 0 ]; then
                echo "File '$FILE_NAME' uploaded successfully!"
            else
                echo "Error: Failed to upload file '$FILE_NAME'."
            fi
        fi
    done
    ------ Post added on Jan 30, 2024 at 11:02 PM
     
    • Like
    Reactions: DevOps_Boy

    DevOps_Boy

    Active member
  • Jul 28, 2023
    238
    120
    43
    Help කරපු හැමෝටම thanks. මේක වැඩ කරන විදියට හදාගත්ත.