[AWS Datasync] DataSync๋ฅผ ์ด์šฉํ•œ S3 ๊ฐ„ ๋ฐ์ดํ„ฐ ๋ณต์‚ฌ

2024. 1. 14. 19:57ใ†AWS

โ˜„๏ธ ๊ฐœ์š”

S3 ๋ฒ„ํ‚ท์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ™์€ ๊ณ„์ •, ๊ฐ™์€ ๋ฆฌ์ „์— ์žˆ๋Š” ๋‹ค๋ฅธ S3 ๋ฒ„ํ‚ท์œผ๋กœ ์˜ฎ๊ฒจ์•ผ ํ•œ๋‹ค.

# aws s3 cp <LocalPath> <S3Uri> or <S3Uri> <LocalPath> or <S3Uri> <S3Uri>
# cp: ์—…๋กœ๋“œ/๋‹ค์šด๋กœ๋“œ & rsync: ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ๋งŒ ์ถ”์ ํ•˜์—ฌ ์—…๋กœ๋“œ/๋‹ค์šด๋กœ๋“œ
aws s3 cp {source} {destination} --recursive

S3 CLI (aws s3 cp)๋กœ ๋กœ์ปฌ์— ๋‹ค์šด๋กœ๋“œ ํ›„ ๋‹ค์‹œ ๋ชฉ์ ์ง€ ๋ฒ„ํ‚ท์— ๋ฐ์ดํ„ฐ๋ฅผ ์—…๋กœ๋“œํ•˜๊ธฐ์—๋Š” ๋ฐ์ดํ„ฐ ์–‘์ด ๋งŽ์•„ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ด์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค.

 

 

๐Ÿ’ก AWS DataSync๋ž€?

ํŒŒ์ผ ๋˜๋Š” ๊ฐ์ฒด ๋ฐ์ดํ„ฐ๋ฅผ AWS ์Šคํ† ๋ฆฌ์ง€ ์„œ๋น„์Šค ๊ฐ„์— ๋น ๋ฅด๊ณ , ์‰ฝ๊ณ , ์•ˆ์ „ํ•˜๊ฒŒ ์ „์†กํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜๋Š” ์˜จ๋ผ์ธ ๋ฐ์ดํ„ฐ ์ด๋™ ๋ฐ ๊ฒ€์ƒ‰ ์„œ๋น„์Šค์ด๋‹ค. ๋ฐ์ดํ„ฐ ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜์„ ๊ฐ„์†Œํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜จํ”„๋ ˆ๋ฏธ์Šค ์Šคํ† ๋ฆฌ์ง€↔AWS, AWS ์Šคํ† ๋ฆฌ์ง€ ์„œ๋น„์Šค ๊ฐ„(ํƒ€ ๋ฆฌ์ „ ๊ฐ„์—๋„ ๊ฐ€๋Šฅ), ํƒ€ cloud ์Šคํ† ๋ฆฌ์ง€ ์„œ๋น„์Šค↔AWS ์Šคํ† ๋ฆฌ์ง€ ์„œ๋น„์Šค ๊ฐ„ ๋ฐ์ดํ„ฐ ์ด๋™์ด ๊ฐ€๋Šฅํ•˜๋‹ค. AWS DataSync๋กœ ์ด๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ ์œ„์น˜๋Š” ์—ฌ๊ธฐ์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. DataSync๋ฅผ ์ด์šฉํ•˜๋ฉด ์ „์†กํ•  ๋ฐ์ดํ„ฐ์˜ ํŒŒ์ผ ํ™•์žฅ์ž, ๊ฐ์ฒด ๋ฐ ํด๋” ํŒจํ„ด์„ ํ•„ํ„ฐ๋งํ•˜์—ฌ ์ „์†กํ•  ์ˆ˜ ์žˆ๋‹ค.

 


 

 

๐Ÿ”ซ  ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

1. IAM Role ์ƒ์„ฑํ•˜๊ธฐ

Datasync ์„œ๋น„์Šค์— ๋ถ€์—ฌํ•  IAM ์—ญํ• ์„ ์ƒ์„ฑํ•œ๋‹ค. ์—ญํ• ์— AWS Managed Policy์ธ AWSDataSyncFullAccess์™€ AWSDataSyncReadOnlyAccess๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค. ์ถ”๊ฐ€๋กœ ๋ชฉ์ ์ง€์™€ ์ถœ๋ฐœ์ง€๊ฐ€ ๋  S3 ๋ฒ„ํ‚ท์„ ๋ช…์‹œํ•œ ์•„๋ž˜ inline ์ •์ฑ…์„ ์—ฐ๊ฒฐํ•œ๋‹ค. Resource์˜ S3 ๋ฒ„ํ‚ท ARN์„ ๋‹ค๋ฅด๊ฒŒ ์ž‘์„ฑํ•˜์—ฌ ์ถœ๋ฐœ์ง€์™€ ๋ชฉ์ ์ง€ bucket์˜ ๊ถŒํ•œ์„ ๊ฐ๊ฐ ๋ถ„๋ฆฌํ•ด์„œ ์ ์šฉํ•ด์ฃผ๋Š” ๊ฒƒ๋„ ์ข‹๋‹ค. ๋‹จ, s3:GetBucketLocation, s3:ListBucket, s3:ListBucketMultipartUploads๋Š” ์ถœ๋ฐœ์ง€, ๋ชฉ์ ์ง€ ๋ฒ„ํ‚ท์— ๊ณตํ†ต์œผ๋กœ ํ—ˆ์šฉํ•ด์•ผ ํ•œ๋‹ค.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "s3:GetBucketLocation",
                "s3:ListBucket",
                "s3:ListBucketMultipartUploads"
            ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::{bucket-name}"
        },
        {
            "Action": [
                "s3:AbortMultipartUpload",
                "s3:DeleteObject",
                "s3:GetObject",
                "s3:ListMultipartUploadParts",
                "s3:GetObjectTagging",
                "s3:PutObjectTagging",
                "s3:PutObject"
              ],
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::{bucket-name}/*"
        }
    ]
}

์‹ ๋ขฐ ๊ด€๊ณ„๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ ์šฉํ•œ๋‹ค.

// Trust Relationship
{
    "Version": "2012-10-17",
    "Statement": [{
        "Effect": "Allow",
        "Principal": {
            "Service": "datasync.amazonaws.com"
        },
        "Action": "sts:AssumeRole",
        "Condition": {
            "StringEquals": {
                "aws:SourceAccount": "{account-id}"
            },
            "StringLike": {
                "aws:SourceArn": "arn:aws:datasync:{region}:{account-id}:*"
            }
        }
    }]
}

 

2. DataSync Location ์ƒ์„ฑํ•˜๊ธฐ

์ถœ๋ฐœ์ง€, ๋ชฉ์ ์ง€ ๋ณ„ Location(๋ฐ์ดํ„ฐ ์ „์†ก ์œ„์น˜)์„ ์ƒ์„ฑํ•œ๋‹ค. S3๋กœ location type ์ง€์ • ์‹œ, ์ด๋™ํ•  ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋Š” folder prefix๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

3. DataSync Task ์ƒ์„ฑํ•˜๊ธฐ

DataSync Task๋Š” Datasync๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•˜๋Š” ์ถœ๋ฐœ์ง€์™€ ๋ชฉ์ ์ง€, ์ „์†ก ๋ฐฉ๋ฒ•์„ ๊ตฌ์„ฑํ•œ๋‹ค. ํŠน์ • ํด๋”๋ฅผ ์ œ์™ธํ•˜๊ฑฐ๋‚˜ ํŠน์ • ํŒŒ์ผ ํ˜•์‹๋งŒ ํฌํ•จํ•˜๋Š” ๊ฒƒ๊ณผ ๊ฐ™์ด ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋งŒ ๋ณต์‚ฌํ•  ์ˆ˜ ์žˆ๋„๋ก task๋ฅผ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๋˜๋Š” ๋ณ€๊ฒฝ๋œ ๋ฐ์ดํ„ฐ๋งŒ ์ „์†กํ•  ์ˆ˜๋„ ์žˆ๋‹ค. (์„ ํƒ) CloudWatch Log Group์— ๋กœ๊น…์„ ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋กœ๊ทธ ๊ทธ๋ฃน ์ง€์ • ๋ฐ 1์—์„œ ์ƒ์„ฑํ•œ Role์— cloudwatch log group์— ๋กœ๊น… ๊ถŒํ•œ์„ ์ถ”๊ฐ€๋กœ ๋ถ€์—ฌํ•ด์•ผ ํ•œ๋‹ค.

Task ์ƒ์„ฑ ํ›„, Start > Start with defaults ๋ฒ„ํŠผ์„ ์„ ํƒํ•˜์—ฌ ๋ฐ์ดํ„ฐ ์ „์†ก์„ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ๋‹ค. 

 

 

๐Ÿ“ ๋Š๋‚€ ์ 

Source S3 ๋ฒ„ํ‚ท์— ๋ฐ์ดํ„ฐ๊ฐ€ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์Œ“์ด์ง€ ์•Š์•„ ๋‹จ ํ•œ ๋ฒˆ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ™์€ ๋ฆฌ์ „, ๊ฐ™์€ ๊ณ„์ •์˜ ๋ฒ„ํ‚ท์— ์ผ๊ด„ ๋ณต์‚ฌํ•˜๋ฉด ๋˜๋Š” ๊ฐ„๋‹จํ•œ ์ž‘์—…์ด์—ˆ๋Š”๋ฐ, DataSync๋ฅผ ํ†ตํ•ด ๋”์šฑ ๊ฐ„ํŽธํ•˜๊ฒŒ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ๋ฐ์ดํ„ฐ ๋ณต์‚ฌ ์„ฑ๊ณต ~ ๐Ÿ˜‡

 


 

๐Ÿ”— ์ฐธ๊ณ  ๋งํฌ

  1. AWS Docs: What is AWS DataSync?
  2. AWS Docs: Configuring AWS DataSync transfers with Amazon S3
  3. AWS Repost: Why can't I copy an object between two Amazon S3 buckets?