feat(user/mp4_make480.sh):Use GNU parallel, split into functions
[BK-2020-03.git] / user / rsync_tranches.sh
index 0456daa30969ba2dc09135088ae80bc78896046f..bcae90e2db8c17a89f4f287b9a7ef7323f3ea6b8 100644 (file)
@@ -7,7 +7,7 @@ function rsync_tranches() {
     # Desc: Runs rsync in parallel across different files size ranges
     # Example: rsync_tranches -avu --progress --dry-run ./SOURCE/ ./DEST/
     # Depends: rsync 3.2.7
-    # Version: 0.0.3
+    # Version: 0.1.1
     local -a rsync_opts=();
     local source dest;
 
@@ -20,7 +20,13 @@ function rsync_tranches() {
                 shift;
                 ;;
             *)
-                if [ -z "$source" ]; then
+                ## If not a file or directory, assume option
+                if [[ ! -f "$1" ]] && [[ ! -d "$1" ]]; then
+                    rsync_opts+=("$1");
+                    shift;
+                fi;
+                ## If valid file or directory, assume source or dest path
+                if [[ -z "$source" ]]; then
                     source="$1";
                 else
                     dest="$1";
@@ -37,11 +43,11 @@ function rsync_tranches() {
     fi;
 
     # Tranche 1: 0 to 1MiB-1
-    rsync --min-size='0' --max-size='1MiB-1' "${rsync_opts[@]}" "$source" "$dest";
+    rsync --min-size='0' --max-size='1MiB-1' "${rsync_opts[@]}" "$source" "$dest" &
+    sleep 2;
 
     # Tranche 2: 1MiB to 2MiB-1
     rsync --min-size='1MiB' --max-size='2MiB-1' "${rsync_opts[@]}" "$source" "$dest" &
-    sleep 1;
 
     # Tranche 3: 2MiB to 4MiB-1
     rsync --min-size='2MiB' --max-size='4MiB-1' "${rsync_opts[@]}" "$source" "$dest" &