반응형
우분투 22.04에서 rclone을 설치하고 AWS S3와 동기화하는 방법
1. rclone 설치
sudo apt update
sudo apt install -y curl
스크립트 다운로드 및 설치
sudo -v ; curl https://rclone.org/install.sh | sudo bash
더보기
---
공식 사이트에서 최신 버전을 다운로드해 수동 설치
curl -O https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
cd rclone-*-linux-amd64
sudo cp rclone /usr/bin/
sudo chown root:root /usr/bin/rclone
sudo chmod 755 /usr/bin/rclone
---
설치 확인
rclone version
rclone v1.69.2
- os/version: ubuntu 22.04 (64 bit)
- os/kernel: 5.15.0-136-generic (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.24.2
- go/linking: static
- go/tags: none
2. AWS S3 설정
AWS IAM 사용자 생성
rclone 설정
rclone config
2025/05/15 12:58:33 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
Enter name for new remote.
name> aws-s3
Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
Storage> s3
Option provider.
Choose your S3 provider.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
provider> AWS
Option env_auth.
Get AWS credentials from runtime (environment variables or EC2/ECS meta data if no env vars).
Only applies if access_key_id and secret_access_key is blank.
Choose a number from below, or type in your own boolean value (true or false).
Press Enter for the default (false).
env_auth> true
Option access_key_id.
AWS Access Key ID.
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
access_key_id> Access-Key-ID
Option secret_access_key.
AWS Secret Access Key (password).
Leave blank for anonymous access or runtime credentials.
Enter a value. Press Enter to leave empty.
secret_access_key> Secret-Access-Key
Option region.
Region to connect to.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
region> ap-northeast-2
Option endpoint.
Endpoint for S3 API.
Leave blank if using AWS to use the default endpoint for the region.
Enter a value. Press Enter to leave empty.
endpoint>
Option location_constraint.
Location constraint - must be set to match the Region.
Used when creating buckets only.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
location_constraint> ap-northeast-2
Option acl.
Canned ACL used when creating buckets and storing or copying objects.
This ACL is used for creating objects and if bucket_acl isn't set, for creating buckets too.
For more info visit https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl
Note that this ACL is applied when server-side copying objects as S3
doesn't copy the ACL from the source but rather writes a fresh one.
If the acl is an empty string then no X-Amz-Acl: header is added and
the default (private) will be used.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
acl> 1
Option server_side_encryption.
The server-side encryption algorithm used when storing this object in S3.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
server_side_encryption> 1
Option sse_kms_key_id.
If using KMS ID you must provide the ARN of Key.
Choose a number from below, or type in your own value.
Press Enter to leave empty.
storage_class> 1
Edit advanced config?
y) Yes
n) No (default)
y/n> n
Configuration complete.
Options:
- type: s3
- provider: AWS
- env_auth: true
- access_key_id: Access-Key-ID
- secret_access_key: Secret-Access-Key
- region: ap-northeast-2
- location_constraint: ap-northeast-2
- acl: private
Keep this "aws-s3" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Current remotes:
Name Type
==== ====
aws-s3 s3
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
cat /root/.config/rclone/rclone.conf
[aws-s3]
type = s3
provider = AWS
env_auth = true
access_key_id = Access-Key-ID
secret_access_key = Secret-Access-Key
region = ap-northeast-2
location_constraint = ap-northeast-2
acl = private
728x90
설정 과정
- n → 새 remote 추가
- 이름 입력 (예: aws-s3)
- Storage 선택 → s3
- Provider 선택 → AWS
- AWS Access Key 입력
- AWS Secret Key 입력
- Region 입력 (예: ap-northeast-2 = 서울)
- Endpoint 입력 (보통 비워두면 자동 설정)
- Advanced config? → n
- Auto config? → y
설정 완료되면 aws-s3 remote가 생성됩니다.
3. S3와 동기화
버킷 목록 확인
rclone lsd s3remote:
로컬 폴더와 S3 동기화
- 로컬 폴더(예: /path/to/local)를 S3 버킷(예: my-bucket)에 업로드
rclone sync /mnt/data aws-s3:my-bucket --progress
더보기
---
sync는 S3에 없는 파일을 삭제하므로 주의! 삭제 없이 올리려면 copy 사용
rclone copy /mnt/data aws-s3:my-bucket --progress
---
- S3 버킷에서 로컬 폴더로 다운로드
rclone sync aws-s3:my-bucket /mnt/data --progress
옵션
rclone sync /mnt/data aws-s3:my-bucket --progress --dry-run
- --progress : 진행 상황 표시
- --bwlimit 10M : 업로드 속도 제한
- --checksum : 시간 대신 해시 비교
- --transfers=4 : 동시 전송 수 제한
- --log-file=/path/to/log.txt : 로그 저장
- --dry-run : 실제 실행 전 변경 사항 미리보기
- --exclude "파일패턴" : 특정 파일 제외
4. 자동화
crontab -e
0 * * * * /usr/bin/rclone sync /mnt/data aws-s3:my-bucket --log-file=/var/log/awss3bucket.log
5. 동기화하는 자동 스크립트
스크립트 작성
vim rclone_sync_to_s3.sh
#!/bin/bash
# ──────────────────────────────────────────────
# rclone 자동 동기화 스크립트
# - 이어받기 지원
# - 증분 업로드
# - 속도 제한
# - 로그 기록
# ──────────────────────────────────────────────
# 설정 변수
LOCAL_DIR="/mnt/data" # 동기화할 로컬 디렉터리
S3_REMOTE_NAME="aws-s3" # rclone remote 이름 (rclone config에서 지정한 이름)
S3_BUCKET_PATH="my-bucket/data" # 업로드 대상 S3 경로
LOG_FILE="/var/log/rclone_sync.log" # 로그 파일 경로
BW_LIMIT="20M" # 업로드 대역폭 제한 (예: 20M = 20MB/s)
TRANSFERS="8" # 동시 전송 개수
DATE_NOW=$(date "+%Y-%m-%d %H:%M:%S")
# 로그 시작
echo "[$DATE_NOW] rclone sync 시작" >> "$LOG_FILE"
# rclone 동기화 실행
/usr/bin/rclone sync "$LOCAL_DIR" "$S3_REMOTE_NAME:$S3_BUCKET_PATH" \
--bwlimit "$BW_LIMIT" \
--transfers "$TRANSFERS" \
--log-file="$LOG_FILE" \
--log-level INFO \
--progress
# 완료 로그
DATE_DONE=$(date "+%Y-%m-%d %H:%M:%S")
echo "[$DATE_DONE] rclone sync 완료" >> "$LOG_FILE"
실행 권한 부여
chmod +x rclone_sync_to_s3.sh
스크립트 실행
./rclone_sync_to_s3.sh
참고URL
- Rclone Documentation : Install
- GitHub Rclone : rclone download(rclone v1.69.2)
반응형
'퍼블릭 클라우드' 카테고리의 다른 글
Amazon EC2 인스턴스에 CloudWatch Agent를 설치하는 방법 (1) | 2025.05.05 |
---|---|
AWS EC2 인스턴스에서 Swap 메모리를 사용하지 않는 이유 (0) | 2025.05.05 |
AWS에서 S3에 접근하는 두 가지 주요 방법 (0) | 2025.05.01 |
AWS IAM 사용자에게 MFA 강제 적용하고 정책과 MFA 디바이스를 스스로 관리 설정하는 정책 (0) | 2025.04.29 |
AWS Management Console 접근을 소스 IP 기반으로 제한하는 방법 (0) | 2025.04.29 |