rsync
rsync sync implementation. Relies on the user having rsync installed on their system
pull(remote_uri, local_path, exclude, dry_run, use_daemon=False, timeout=None, delete=True, verbosity=0, rsync_args=None)
Sync an upstream file or folder into the specified location using rsync. This will overwrite any files and folders already at the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_uri |
ParseResult
|
The URI for the remote resource to copy from |
required |
local_path |
Path
|
The destination folder |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
use_daemon |
bool
|
By default, the rsync is performed over ssh. If you happen to have an
rsync daemon running on your system, however, you're welcome to leverage
it instead by passing in |
False
|
timeout |
int
|
The number of seconds to wait before timing out the sync operation. If None is provided, no explicit timeout value will be set. |
None
|
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. Default is True. |
True
|
verbosity |
int
|
A modifier for how much info to output either to stdout or the INFO-level logs. Defaults to 0. |
0
|
rsync_args |
Iterable[str] | None
|
Any additional arguments to pass into rsync. Note that rsync is run by
default with the flags: |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the destination folder does not exist |
Notes
- This method does not provide for interactive authentication. If using rsync over SSH, you'll need to be set up for password-less (key-based) access.
- If the destination folder does not already exist, this method will not create it or its parent directories.
Source code in enderchest/sync/rsync.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
push(local_path, remote_uri, exclude, dry_run, use_daemon=False, timeout=None, delete=True, verbosity=0, rsync_args=None)
Sync a local file or folder into the specified location using rsync. This will overwrite any files and folders already at the destination.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_path |
Path
|
The file or folder to copy |
required |
remote_uri |
ParseResult
|
The URI for the remote location to copy into |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
use_daemon |
bool
|
By default, the rsync is performed over ssh. If you happen to have an
rsync daemon running on your system, however, you're welcome to leverage
it instead by passing in |
False
|
timeout |
int
|
The number of seconds to wait before timing out the sync operation. If None is provided, no explicit timeout value will be set. |
None
|
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source. Default is True. |
True
|
verbosity |
int
|
A modifier for how much info to output either to stdout or the INFO-level logs. Defaults to 0. |
0
|
rsync_args |
Iterable[str] | None
|
Any additional arguments to pass into rsync. Note that rsync is run by
default with the flags: |
None
|
Notes
- This method does not provide for interactive authentication. If using rsync over SSH, you'll need to be set up for password-less (key-based) access.
- If the destination folder does not already exist, this method will very likely fail.
Source code in enderchest/sync/rsync.py
run_rsync(working_directory, source, destination_folder, delete, dry_run, exclude, *additional_args, timeout=None, verbosity=0, rsync_flags=None)
Run an operation with rsync
Parameters:
Name | Type | Description | Default |
---|---|---|---|
working_directory |
Path
|
The working directory to run the sync command from |
required |
source |
str
|
The source file or folder to sync, specified as either a URI string, an ssh address or a path relative to the working directory |
required |
destination_folder |
str
|
The destination folder where the file or folder should be synced to, with the same formats available as for source |
required |
delete |
bool
|
Whether part of the syncing should include deleting files at the destination that aren't at the source |
required |
dry_run |
bool
|
Whether to only simulate this sync (report the operations to be performed but not actually perform them) |
required |
exclude |
list of str
|
Any patterns that should be excluded from the sync (and sync) |
required |
*additional_args |
str
|
Any additional arguments to pass into the rsync command |
()
|
timeout |
int
|
The number of seconds to wait before timing out the sync operation. If None is provided, no explicit timeout value will be set. |
None
|
verbosity |
int
|
A modifier for how much info to output either to stdout or the INFO-level logs. At...
Verbosity values outside of this range will simply be capped / floored to [-2, 2]. |
0
|
rsync_flags |
str
|
By default, rsync will be run using the flags "shaz" which means:
Advanced users may choose to override these options, but you do so at your own peril. |
None
|
Raises:
Type | Description |
---|---|
TimeoutError
|
If the rsync operation times out before completion |
RuntimeError
|
If the rsync operation fails for any other reason |
Notes
This method does not perform any validation or normalization of the source, destination, exclude-list, additional arguments or rsync options.
Source code in enderchest/sync/rsync.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
summarize_rsync_report(raw_output, depth=2)
Take the captured output from running
rsync -ha --out-format="%i %n"
and report a high-level summary to the logging.INFO level
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_output |
str
|
The raw output captured from running the rsync command |
required |
depth |
int
|
How many directories to go down from the root to generate the summary. Default is 2 (just report on top-level files and folders within the source folder). |
2
|
Returns:
Type | Description |
---|---|
list of str
|
Any lines that weren't part of the rsync report (and were probably
part of |
Notes
The rsync man page (https://linux.die.net/man/1/rsync) describes the output
format as... "cryptic," which I find rather charitable. The relevant bits
are that --out-format="%i %n"
produces:
- %i
: a string of 11 characters that gives various metadata about the file
transfer operation (is it a file, a directory or a link? Is it being
sent or received? Created, updated or deleted?)
- %n
: the path of the file (or whatever), unquoted, un-escaped
Source code in enderchest/sync/rsync.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|