github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/docs/content/union.md (about) 1 --- 2 title: "Union" 3 description: "Remote Unification" 4 versionIntroduced: "v1.44" 5 --- 6 7 # {{< icon "fa fa-link" >}} Union 8 9 The `union` backend joins several remotes together to make a single unified view of them. 10 11 During the initial setup with `rclone config` you will specify the upstream 12 remotes as a space separated list. The upstream remotes can either be a local 13 paths or other remotes. 14 15 The attributes `:ro`, `:nc` and `:writeback` can be attached to the end of the remote 16 to tag the remote as **read only**, **no create** or **writeback**, e.g. 17 `remote:directory/subdirectory:ro` or `remote:directory/subdirectory:nc`. 18 19 - `:ro` means files will only be read from here and never written 20 - `:nc` means new files or directories won't be created here 21 - `:writeback` means files found in different remotes will be written back here. See the [writeback section](#writeback) for more info. 22 23 Subfolders can be used in upstream remotes. Assume a union remote named `backup` 24 with the remotes `mydrive:private/backup`. Invoking `rclone mkdir backup:desktop` 25 is exactly the same as invoking `rclone mkdir mydrive:private/backup/desktop`. 26 27 There is no special handling of paths containing `..` segments. Invoking `rclone 28 mkdir backup:../desktop` is exactly the same as invoking `rclone mkdir 29 mydrive:private/backup/../desktop`. 30 31 ## Configuration 32 33 Here is an example of how to make a union called `remote` for local folders. 34 First run: 35 36 rclone config 37 38 This will guide you through an interactive setup process: 39 40 ``` 41 No remotes found, make a new one? 42 n) New remote 43 s) Set configuration password 44 q) Quit config 45 n/s/q> n 46 name> remote 47 Type of storage to configure. 48 Choose a number from below, or type in your own value 49 [snip] 50 XX / Union merges the contents of several remotes 51 \ "union" 52 [snip] 53 Storage> union 54 List of space separated upstreams. 55 Can be 'upstreama:test/dir upstreamb:', '\"upstreama:test/space:ro dir\" upstreamb:', etc. 56 Enter a string value. Press Enter for the default (""). 57 upstreams> remote1:dir1 remote2:dir2 remote3:dir3 58 Policy to choose upstream on ACTION class. 59 Enter a string value. Press Enter for the default ("epall"). 60 action_policy> 61 Policy to choose upstream on CREATE class. 62 Enter a string value. Press Enter for the default ("epmfs"). 63 create_policy> 64 Policy to choose upstream on SEARCH class. 65 Enter a string value. Press Enter for the default ("ff"). 66 search_policy> 67 Cache time of usage and free space (in seconds). This option is only useful when a path preserving policy is used. 68 Enter a signed integer. Press Enter for the default ("120"). 69 cache_time> 70 Remote config 71 -------------------- 72 [remote] 73 type = union 74 upstreams = remote1:dir1 remote2:dir2 remote3:dir3 75 -------------------- 76 y) Yes this is OK 77 e) Edit this remote 78 d) Delete this remote 79 y/e/d> y 80 Current remotes: 81 82 Name Type 83 ==== ==== 84 remote union 85 86 e) Edit existing remote 87 n) New remote 88 d) Delete remote 89 r) Rename remote 90 c) Copy remote 91 s) Set configuration password 92 q) Quit config 93 e/n/d/r/c/s/q> q 94 ``` 95 96 Once configured you can then use `rclone` like this, 97 98 List directories in top level in `remote1:dir1`, `remote2:dir2` and `remote3:dir3` 99 100 rclone lsd remote: 101 102 List all the files in `remote1:dir1`, `remote2:dir2` and `remote3:dir3` 103 104 rclone ls remote: 105 106 Copy another local directory to the union directory called source, which will be placed into `remote3:dir3` 107 108 rclone copy C:\source remote:source 109 110 ### Behavior / Policies 111 112 The behavior of union backend is inspired by [trapexit/mergerfs](https://github.com/trapexit/mergerfs). All functions are grouped into 3 categories: **action**, **create** and **search**. These functions and categories can be assigned a policy which dictates what file or directory is chosen when performing that behavior. Any policy can be assigned to a function or category though some may not be very useful in practice. For instance: **rand** (random) may be useful for file creation (create) but could lead to very odd behavior if used for `delete` if there were more than one copy of the file. 113 114 ### Function / Category classifications 115 116 | Category | Description | Functions | 117 |----------|--------------------------|-------------------------------------------------------------------------------------| 118 | action | Writing Existing file | move, rmdir, rmdirs, delete, purge and copy, sync (as destination when file exist) | 119 | create | Create non-existing file | copy, sync (as destination when file not exist) | 120 | search | Reading and listing file | ls, lsd, lsl, cat, md5sum, sha1sum and copy, sync (as source) | 121 | N/A | | size, about | 122 123 ### Path Preservation 124 125 Policies, as described below, are of two basic types. `path preserving` and `non-path preserving`. 126 127 All policies which start with `ep` (**epff**, **eplfs**, **eplus**, **epmfs**, **eprand**) are `path preserving`. `ep` stands for `existing path`. 128 129 A path preserving policy will only consider upstreams where the relative path being accessed already exists. 130 131 When using non-path preserving policies paths will be created in target upstreams as necessary. 132 133 ### Quota Relevant Policies 134 135 Some policies rely on quota information. These policies should be used only if your upstreams support the respective quota fields. 136 137 | Policy | Required Field | 138 |------------|----------------| 139 | lfs, eplfs | Free | 140 | mfs, epmfs | Free | 141 | lus, eplus | Used | 142 | lno, eplno | Objects | 143 144 To check if your upstream supports the field, run `rclone about remote: [flags]` and see if the required field exists. 145 146 ### Filters 147 148 Policies basically search upstream remotes and create a list of files / paths for functions to work on. The policy is responsible for filtering and sorting. The policy type defines the sorting but filtering is mostly uniform as described below. 149 150 * No **search** policies filter. 151 * All **action** policies will filter out remotes which are tagged as **read-only**. 152 * All **create** policies will filter out remotes which are tagged **read-only** or **no-create**. 153 154 If all remotes are filtered an error will be returned. 155 156 ### Policy descriptions 157 158 The policies definition are inspired by [trapexit/mergerfs](https://github.com/trapexit/mergerfs) but not exactly the same. Some policy definition could be different due to the much larger latency of remote file systems. 159 160 | Policy | Description | 161 |------------------|------------------------------------------------------------| 162 | all | Search category: same as **epall**. Action category: same as **epall**. Create category: act on all upstreams. | 163 | epall (existing path, all) | Search category: Given this order configured, act on the first one found where the relative path exists. Action category: apply to all found. Create category: act on all upstreams where the relative path exists. | 164 | epff (existing path, first found) | Act on the first one found, by the time upstreams reply, where the relative path exists. | 165 | eplfs (existing path, least free space) | Of all the upstreams on which the relative path exists choose the one with the least free space. | 166 | eplus (existing path, least used space) | Of all the upstreams on which the relative path exists choose the one with the least used space. | 167 | eplno (existing path, least number of objects) | Of all the upstreams on which the relative path exists choose the one with the least number of objects. | 168 | epmfs (existing path, most free space) | Of all the upstreams on which the relative path exists choose the one with the most free space. | 169 | eprand (existing path, random) | Calls **epall** and then randomizes. Returns only one upstream. | 170 | ff (first found) | Search category: same as **epff**. Action category: same as **epff**. Create category: Act on the first one found by the time upstreams reply. | 171 | lfs (least free space) | Search category: same as **eplfs**. Action category: same as **eplfs**. Create category: Pick the upstream with the least available free space. | 172 | lus (least used space) | Search category: same as **eplus**. Action category: same as **eplus**. Create category: Pick the upstream with the least used space. | 173 | lno (least number of objects) | Search category: same as **eplno**. Action category: same as **eplno**. Create category: Pick the upstream with the least number of objects. | 174 | mfs (most free space) | Search category: same as **epmfs**. Action category: same as **epmfs**. Create category: Pick the upstream with the most available free space. | 175 | newest | Pick the file / directory with the largest mtime. | 176 | rand (random) | Calls **all** and then randomizes. Returns only one upstream. | 177 178 179 ### Writeback {#writeback} 180 181 The tag `:writeback` on an upstream remote can be used to make a simple cache 182 system like this: 183 184 ``` 185 [union] 186 type = union 187 action_policy = all 188 create_policy = all 189 search_policy = ff 190 upstreams = /local:writeback remote:dir 191 ``` 192 193 When files are opened for read, if the file is in `remote:dir` but not `/local` 194 then rclone will copy the file entirely into `/local` before returning a 195 reference to the file in `/local`. The copy will be done with the equivalent of 196 `rclone copy` so will use `--multi-thread-streams` if configured. Any copies 197 will be logged with an INFO log. 198 199 When files are written, they will be written to both `remote:dir` and `/local`. 200 201 As many remotes as desired can be added to `upstreams` but there should only be 202 one `:writeback` tag. 203 204 Rclone does not manage the `:writeback` remote in any way other than writing 205 files back to it. So if you need to expire old files or manage the size then you 206 will have to do this yourself. 207 208 {{< rem autogenerated options start" - DO NOT EDIT - instead edit fs.RegInfo in backend/union/union.go then run make backenddocs" >}} 209 ### Standard options 210 211 Here are the Standard options specific to union (Union merges the contents of several upstream fs). 212 213 #### --union-upstreams 214 215 List of space separated upstreams. 216 217 Can be 'upstreama:test/dir upstreamb:', '"upstreama:test/space:ro dir" upstreamb:', etc. 218 219 Properties: 220 221 - Config: upstreams 222 - Env Var: RCLONE_UNION_UPSTREAMS 223 - Type: string 224 - Required: true 225 226 #### --union-action-policy 227 228 Policy to choose upstream on ACTION category. 229 230 Properties: 231 232 - Config: action_policy 233 - Env Var: RCLONE_UNION_ACTION_POLICY 234 - Type: string 235 - Default: "epall" 236 237 #### --union-create-policy 238 239 Policy to choose upstream on CREATE category. 240 241 Properties: 242 243 - Config: create_policy 244 - Env Var: RCLONE_UNION_CREATE_POLICY 245 - Type: string 246 - Default: "epmfs" 247 248 #### --union-search-policy 249 250 Policy to choose upstream on SEARCH category. 251 252 Properties: 253 254 - Config: search_policy 255 - Env Var: RCLONE_UNION_SEARCH_POLICY 256 - Type: string 257 - Default: "ff" 258 259 #### --union-cache-time 260 261 Cache time of usage and free space (in seconds). 262 263 This option is only useful when a path preserving policy is used. 264 265 Properties: 266 267 - Config: cache_time 268 - Env Var: RCLONE_UNION_CACHE_TIME 269 - Type: int 270 - Default: 120 271 272 ### Advanced options 273 274 Here are the Advanced options specific to union (Union merges the contents of several upstream fs). 275 276 #### --union-min-free-space 277 278 Minimum viable free space for lfs/eplfs policies. 279 280 If a remote has less than this much free space then it won't be 281 considered for use in lfs or eplfs policies. 282 283 Properties: 284 285 - Config: min_free_space 286 - Env Var: RCLONE_UNION_MIN_FREE_SPACE 287 - Type: SizeSuffix 288 - Default: 1Gi 289 290 #### --union-description 291 292 Description of the remote 293 294 Properties: 295 296 - Config: description 297 - Env Var: RCLONE_UNION_DESCRIPTION 298 - Type: string 299 - Required: false 300 301 ### Metadata 302 303 Any metadata supported by the underlying remote is read and written. 304 305 See the [metadata](/docs/#metadata) docs for more info. 306 307 {{< rem autogenerated options stop >}}