Last active
January 7, 2016 19:20
-
-
Save greyhoundforty/be7613ec0430c56d8854 to your computer and use it in GitHub Desktop.
Object Storage Upload bash script
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 | |
# ================================================================================ | |
# ObjectStorageUploader.sh | |
# © Copyright IBM Corporation 2014. | |
# LICENSE: MIT (http://opensource.org/licenses/MIT) | |
# ================================================================================ | |
#./objectstorageupload.sh dsl-4.4.10.iso 'myContainer/file.vhd' 'username' 'apikey' | |
fileToUpload=$1 | |
swiftTargetPath=$2 | |
swiftUsername=$3 | |
swiftPassword=$4 | |
swiftEndpoint='https://dal05.objectstorage.softlayer.net/auth/v1.0/' | |
apiResponse=$(curl -X GET -H "X-Storage-User: $swiftUsername" -H "X-Storage-Pass: $swiftPassword" -s -i $swiftEndpoint) | |
swiftAuthToken=$(echo "$apiResponse" | grep "X-Auth-Token:" | sed 's/X-Auth-Token: //g' | sed 's/\r//g') | |
swiftStorageUrl=$(echo "$apiResponse" | grep "X-Storage-Url:" | sed 's/X-Storage-Url: //g' | sed 's/\r//g') | |
fileSize=$(stat -c '%s' $fileToUpload) | |
blockSize=1048576 | |
let chunkSize=2048 #2GB chunks | |
let chunks=($fileSize/$blockSize+$chunkSize-1)/$chunkSize; | |
for ((i=0; i<chunks; i++)) | |
do | |
printf -v chunkName "chunk-%05d" $i | |
let skipChunk=$i*chunkSize | |
dd if=$fileToUpload bs=$blockSize count=$chunkSize skip=$skipChunk | curl -X PUT -H "X-Auth-Token: $swiftAuthToken" --data-binary @- "$swiftStorageUrl/$swiftTargetPath/$chunkName" | |
done | |
curl -X PUT -H "X-Auth-Token: $swiftAuthToken" -H "X-Object-Manifest: $swiftTargetPath" -H "Content-Length: 0" $swiftStorageUrl/$swiftTargetPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment