Created
August 5, 2024 04:26
-
-
Save zaru/ee9a3fb8352638c11ce224a52c4194e4 to your computer and use it in GitHub Desktop.
S3ファイルアップロードとリネームベンチマーク
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# サイズを指定する (1MB = 1048576バイト) | |
FILE_SIZE=1048576 | |
# ディレクトリとファイルを作成する | |
for i in {1..10}; do | |
for j in {1..10}; do | |
mkdir -p ./xxx${i}/yyy${j} | |
done | |
done | |
# 1MBのfile.txtを作成して、全てのディレクトリにコピーする | |
dd if=/dev/zero of=./file.txt bs=1 count=${FILE_SIZE} | |
for i in {1..10}; do | |
for j in {1..10}; do | |
cp ./file.txt ./xxx${i}/yyy${j}/ | |
done | |
done | |
# オリジナルのfile.txtを削除 | |
rm ./file.txt | |
echo "ディレクトリとファイルの作成が完了しました。" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# S3バケット名とアップロード先のパスを指定 | |
BUCKET_NAME="bucket-name" | |
S3_PATH="files" | |
# 変更前のパスと変更後のパス | |
OLD_PATH="xxx" | |
NEW_PATH="zzz" | |
# 開始時間を取得 | |
START_TIME=$(date +%s) | |
# S3オブジェクトのリストを取得してリネームする | |
aws s3 ls s3://${BUCKET_NAME}/${S3_PATH}/ --recursive | awk '{print $4}' | grep "/${OLD_PATH}" | while read -r OBJECT_KEY; do | |
NEW_OBJECT_KEY=$(echo ${OBJECT_KEY} | sed "s|\/${OLD_PATH}|\/${NEW_PATH}|") | |
aws s3 mv s3://${BUCKET_NAME}/${OBJECT_KEY} s3://${BUCKET_NAME}/${NEW_OBJECT_KEY} | |
done | |
# 終了時間を取得 | |
END_TIME=$(date +%s) | |
# 経過時間を計算 | |
ELAPSED_TIME=$(($END_TIME - $START_TIME)) | |
echo "ディレクトリ名の変更が完了しました。" | |
echo "リネームにかかった時間: ${ELAPSED_TIME}秒" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# S3バケット名とアップロード先のパスを指定 | |
BUCKET_NAME="bucket-name" | |
S3_PATH="files" | |
# 開始時間を取得 | |
START_TIME=$(date +%s) | |
# ローカルディレクトリをS3に同期 | |
aws s3 sync ./ s3://${BUCKET_NAME}/${S3_PATH} --exclude "*" --include "xxx*/yyy*/file.txt" | |
# 終了時間を取得 | |
END_TIME=$(date +%s) | |
# 経過時間を計算 | |
ELAPSED_TIME=$(($END_TIME - $START_TIME)) | |
echo "ディレクトリのS3への同期が完了しました。" | |
echo "アップロードにかかった時間: ${ELAPSED_TIME}秒" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment