Permalink
Browse files

uploader.sh new: support large objects, added "segment size" param, c…

…heck existence of local directory and remote container
  • Loading branch information...
1 parent a6d071a commit 928ea4459743dd921555635f3817f18854f30fb2 @vills vills committed with Stanislav Bogatyrev Jul 26, 2012
Showing with 40 additions and 8 deletions.
  1. +40 −8 uploader.sh
View
@@ -15,20 +15,36 @@ fi
DIR="$1"
CNT="$2"
+if [ -n "$4" ]; then
+ PREF_SSIZE="$4"
+fi
+
if [[ -z "$DIR" || -z "$CNT" ]]; then
- echo "Usage: $0 <local dir> <remote cont>"
+ echo "Usage: $0 <local dir> <remote cont> [segment size]"
+ echo "Example: $0 /usr/share public"
exit 1
fi
D1=`dirname $DIR`
D2=`basename $DIR`
DIR="$D1/$D2"
+if [[ ! -d $DIR ]]; then
+ echo "$DIR is not a directory"
+ exit 1
+fi
+
echo -ne "Authenticating..."
if authenticate $STORAGE_USER $STORAGE_KEY; then
echo -ne "done\n"
else
echo -ne "failed\n"
+ exit 1
+fi
+
+if ! check_container_exists "$CNT"; then
+ error "Container $CNT does not exist"
+ exit 2
fi
echo "Creating directories from $DIR..."
@@ -48,16 +64,32 @@ flist=`find $DIR -type f | sed "s%$DIR/%%"`
echo "$flist" | while read file
do
echo -ne "$CNT/$file ... "
- if put_obj "$CNT" "$file" "$DIR/$file"; then
- echo -ne "OK\n"
- else
- echo -ne "Retry in 10s\n"
- sleep 10
+
+ # check if filesize more than segment size
+ LSZ=`stat -c %s "$DIR/$file"`
+ if [ $(( $LSZ / $PREF_SSIZE)) -gt 2 ]; then
+ if put_obj_large "$CNT" "$file" "$DIR/$file" "$PREF_SSIZE"; then
+ echo -ne "OK\n"
+ else
+ echo -ne "Retry in 10s\n"
+ sleep 10
+ if put_obj_large "$CNT" "$file" "$DIR/$file" "$PREF_SSIZE"; then
+ echo -ne "OK\n"
+ else
+ echo -ne "FAIL\n"
+ fi
+ fi
+ else
if put_obj "$CNT" "$file" "$DIR/$file"; then
echo -ne "OK\n"
else
- echo -ne "FAIL\n"
+ echo -ne "Retry in 10s\n"
+ sleep 10
+ if put_obj "$CNT" "$file" "$DIR/$file"; then
+ echo -ne "OK\n"
+ else
+ echo -ne "FAIL\n"
+ fi
fi
fi
-
done

0 comments on commit 928ea44

Please sign in to comment.