Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added upload rate limit #545

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,31 @@ Print some info about the space usage on your Dropbox account
Unlink the script from your Dropbox account


**Optional parameters:**
* **-f <FILENAME>**
**Optional parameters:**
* **-f <FILENAME>**
Load the configuration file from a specific file

* **-s**
* **-s**
Skip already existing files when download/upload. Default: Overwrite

* **-d**
* **-d**
Enable DEBUG mode

* **-q**
* **-q**
Quiet mode. Don't show progress meter or messages

* **-h**
* **-h**
Show file sizes in human readable format

* **-p**
* **-p**
Show cURL progress meter

* **-k**
* **-k**
Doesn't check for SSL certificates (insecure)

* **-l**
Upload rate limit (e.g. 10M limits the upload bandwidth to 10MiB/s)

* **-x <FILENAME>**
Ignores/excludes directories or files from syncing.
-x filename -x directoryname.
Expand Down
13 changes: 11 additions & 2 deletions dropbox_uploader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if [[ ! -d "$TMP_DIR" ]]; then
fi

#Look for optional config file parameter
while getopts ":qpskdhf:x:" opt; do
while getopts ":qpskdhf:l:x:" opt; do
case $opt in

f)
Expand Down Expand Up @@ -125,6 +125,10 @@ while getopts ":qpskdhf:x:" opt; do
EXCLUDE+=( $OPTARG )
;;

l)
RATE_LIMIT=$OPTARG
;;

\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
Expand All @@ -138,6 +142,10 @@ while getopts ":qpskdhf:x:" opt; do
esac
done

if [[ ! -z ${RATE_LIMIT+x} ]]; then
RATE_LIMIT="--limit-rate $RATE_LIMIT"
fi

if [[ $DEBUG != 0 ]]; then
echo $VERSION
uname -a 2> /dev/null
Expand Down Expand Up @@ -288,6 +296,7 @@ function usage
echo -e "\t-p Show cURL progress meter"
echo -e "\t-k Doesn't check for SSL certificates (insecure)"
echo -e "\t-x Ignores/excludes directories or files from syncing. -x filename -x directoryname. example: -x .git"
echo -e "\t-l Upload rate limit (e.g. 10M limits the upload bandwidth to 10MiB/s)"

echo -en "\nFor more info and examples, please see the README file.\n\n"
remove_temp_files
Expand Down Expand Up @@ -663,7 +672,7 @@ function db_chunked_upload_file
#Uploading the chunk...
echo > "$RESPONSE_FILE"
ensure_accesstoken
$CURL_BIN $CURL_ACCEPT_CERTIFICATES -X POST $CURL_PARAMETERS --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"cursor\": {\"session_id\": \"$SESSION_ID\",\"offset\": $OFFSET},\"close\": false}" --header "Content-Type: application/octet-stream" --data-binary @"$CHUNK_FILE" "$API_CHUNKED_UPLOAD_APPEND_URL"
$CURL_BIN $CURL_ACCEPT_CERTIFICATES $RATE_LIMIT -X POST $CURL_PARAMETERS --show-error --globoff -i -o "$RESPONSE_FILE" --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" --header "Dropbox-API-Arg: {\"cursor\": {\"session_id\": \"$SESSION_ID\",\"offset\": $OFFSET},\"close\": false}" --header "Content-Type: application/octet-stream" --data-binary @"$CHUNK_FILE" "$API_CHUNKED_UPLOAD_APPEND_URL"
#check_http_response not needed, because we have to retry the request in case of error

#Check
Expand Down