Commit | Line | Data |
---|---|---|
f061ac6b SBS |
1 | #!/usr/bin/env bash |
2 | # Desc: A bash function for splitting up rsync jobs based on size | |
3 | ||
4 | echo "ERROR:This is a bash function, not a script." 2>&1; exit 1; | |
5 | ||
6 | function rsync_tranches() { | |
7 | # Desc: Runs rsync in parallel across different files size ranges | |
8 | # Example: rsync_tranches -avu --progress --dry-run ./SOURCE/ ./DEST/ | |
9 | # Depends: rsync 3.2.7 | |
ec7c9c91 | 10 | # Version: 0.0.2 |
f061ac6b | 11 | local -a rsync_opts=(); |
ec7c9c91 | 12 | local source dest; |
f061ac6b SBS |
13 | |
14 | # Parse arguments until source and destination are found | |
15 | while [[ $# -gt 0 ]]; do | |
16 | case "$1" in | |
17 | # If it's not an option, assume it's the source, then the destination | |
18 | -*) | |
19 | rsync_opts+=("$1"); | |
20 | shift; | |
21 | ;; | |
22 | *) | |
23 | if [ -z "$source" ]; then | |
24 | source="$1"; | |
25 | else | |
26 | dest="$1"; | |
27 | fi; | |
28 | shift; | |
29 | ;; | |
30 | esac; | |
31 | done; | |
32 | ||
33 | # Validate that source and destination are set | |
ec7c9c91 | 34 | if [[ -z "$source" ]] || [[ -z "$dest" ]]; then |
f061ac6b SBS |
35 | echo "Error: Source and destination directories must be specified." 1>&2; |
36 | return 1; | |
37 | fi; | |
38 | ||
39 | # Tranche 1: 0 to 1MiB-1 | |
40 | rsync --min-size='0' --max-size='1MiB-1' "${rsync_opts[@]}" "$source" "$dest" & | |
41 | ||
42 | # Tranche 2: 1MiB to 10MiB-1 | |
43 | rsync --min-size='1MiB' --max-size='10MiB-1' "${rsync_opts[@]}" "$source" "$dest" & | |
44 | ||
45 | # Tranche 3: 10MiB to 100MiB-1 | |
46 | rsync --min-size='10MiB' --max-size='100MiB-1' "${rsync_opts[@]}" "$source" "$dest" & | |
47 | ||
48 | # Tranche 4: Greater than 100MiB | |
49 | rsync --min-size='100MiB' --max-size='8192PiB-1' "${rsync_opts[@]}" "$source" "$dest" & | |
50 | ||
51 | wait # Wait for all rsync processes to complete | |
52 | }; | |
53 | export -f rsync_tranches; | |
4b54193d SBS |
54 | |
55 | # Author: Steven Baltakatei Sandoval | |
56 | # License: GPLv3+ |