Backup, symbols & location¶
Device backup/restore, dyld shared-cache symbol fetching, and GPS simulation.
pymobiledevice3.services.mobilebackup2.Mobilebackup2Service ¶
Bases: LockdownService
Client for the com.apple.mobilebackup2 service, the iTunes/Finder-style device backup protocol.
Drives full and incremental backups, restores, and the related operations (info, list,
extract, unback, change password, erase device) over a DeviceLink channel. Backups can
be filtered to a subset of files via a filter callback, and encrypted backups are
supported (password required for filtering and restore). The right underlying service is
selected automatically: SERVICE_NAME over classic lockdown, or RSD_SERVICE_NAME over
RemoteXPC/RSD.
Inherits async context manager support from LockdownService; use within an
async with block to manage the underlying connection.
Source code in pymobiledevice3/services/mobilebackup2.py
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 217 218 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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 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 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | |
get_will_encrypt
async
¶
Report whether the device is configured to encrypt its backups.
Returns:
| Type | Description |
|---|---|
bool
|
True if backup encryption is enabled on the device, False otherwise (including when the value cannot be read). |
Source code in pymobiledevice3/services/mobilebackup2.py
backup
async
¶
backup(full: bool = True, backup_directory: Union[str, Path] = '.', progress_callback=lambda x: None, filter_callback: Optional[BackupFilterCallback] = None, password: str = '', unback: bool = False) -> None
Back up the device into backup_directory/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full
|
bool
|
Perform a full backup, discarding any previous incremental state. A full backup is also forced when a filter callback is given or when incremental metadata is missing. |
True
|
backup_directory
|
Union[str, Path]
|
Directory the backup is written to (a per-device subdirectory is created under it). |
'.'
|
progress_callback
|
Called as the backup progresses with the completion percentage as its sole argument. |
lambda x: None
|
|
filter_callback
|
Optional[BackupFilterCallback]
|
Optional predicate deciding which backup files to keep; files it rejects are pruned after the backup completes. |
None
|
password
|
str
|
Backup password; required when filtering an encrypted backup. |
''
|
unback
|
bool
|
When True, also unpack the completed backup locally using pyiosbackup. |
False
|
Raises:
| Type | Description |
|---|---|
BackupFilterPasswordRequiredError
|
If a filter callback is given without a password while the device encrypts backups. |
Source code in pymobiledevice3/services/mobilebackup2.py
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 217 218 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 | |
restore
async
¶
restore(backup_directory='.', system: bool = False, reboot: bool = True, copy: bool = True, settings: bool = True, remove: bool = False, password: str = '', source: str = '', progress_callback=lambda x: None, skip_apps: bool = False)
Restore a previously created backup to the device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Path of the backup directory. |
'.'
|
|
system
|
bool
|
Whether to restore system files. |
False
|
reboot
|
bool
|
Reboot the device when done. |
True
|
copy
|
bool
|
Create a copy of the backup folder before restoring. |
True
|
settings
|
bool
|
Restore device settings. |
True
|
remove
|
bool
|
Remove items on the device that aren't part of the restore. |
False
|
password
|
str
|
Password of the backup; required if the backup is encrypted. |
''
|
source
|
str
|
Identifier of the device whose backup is restored; defaults to the connected device's UDID. |
''
|
progress_callback
|
Called as the restore progresses with the completion percentage as its sole argument. |
lambda x: None
|
|
skip_apps
|
bool
|
Do not trigger re-installation of apps after the restore. |
False
|
Source code in pymobiledevice3/services/mobilebackup2.py
info
async
¶
Get information about a backup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Path of the backup directory. |
'.'
|
|
source
|
str
|
Identifier of the device to get info about; defaults to the connected device's UDID. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
Information about the backup, as returned by the device. |
Source code in pymobiledevice3/services/mobilebackup2.py
list
async
¶
List the files in the last backup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Path of the backup directory. |
'.'
|
|
source
|
str
|
Identifier of the device to list; defaults to the connected device's UDID. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
The files and per-file metadata in CSV format. |
Source code in pymobiledevice3/services/mobilebackup2.py
unback
async
¶
Unpack a complete backup into its original device file hierarchy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Path of the backup directory. |
'.'
|
|
password
|
str
|
Password of the backup; required if the backup is encrypted. |
''
|
source
|
str
|
Identifier of the device whose backup is unpacked; defaults to the connected device's UDID. |
''
|
Source code in pymobiledevice3/services/mobilebackup2.py
unback_with_pyiosbackup
staticmethod
¶
Unpack a local backup directory using pyiosbackup, on the host without the device.
The output is written to a sibling directory named <device_directory>.unback,
replacing it if it already exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_directory
|
Path
|
Path of the per-device backup directory to unpack. |
required |
password
|
str
|
Password of the backup; required if the backup is encrypted. |
''
|
Returns:
| Type | Description |
|---|---|
Path
|
Path of the directory the backup was unpacked into. |
Source code in pymobiledevice3/services/mobilebackup2.py
extract
async
¶
extract(domain_name: str, relative_path: str, backup_directory='.', password: str = '', source: str = '') -> None
Extract a single file from a previous backup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_name
|
str
|
The file's domain, e.g. SystemPreferencesDomain or HomeDomain. |
required |
relative_path
|
str
|
Path of the file within the domain. |
required |
backup_directory
|
Path of the backup directory. |
'.'
|
|
password
|
str
|
Password of the backup; required if the backup is encrypted. |
''
|
source
|
str
|
Identifier of the device to extract from; defaults to the connected device's UDID. |
''
|
Source code in pymobiledevice3/services/mobilebackup2.py
change_password
async
¶
Change, enable, or disable the device's backup encryption password.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Path of the backup directory. |
'.'
|
|
old
|
str
|
Previous password. Omit when enabling backup encryption. |
''
|
new
|
str
|
New password. Omit when disabling backup encryption. |
''
|
Source code in pymobiledevice3/services/mobilebackup2.py
erase_device
async
¶
Erase the device, restoring it to factory state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Path of the backup directory used for the device link channel. |
'.'
|
Source code in pymobiledevice3/services/mobilebackup2.py
version_exchange
async
¶
Exchange protocol versions with the device and assert it supports one of ours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dl
|
DeviceLink
|
An initialized device link channel. |
required |
local_versions
|
Protocol versions supported by the host; defaults to
|
None
|
Source code in pymobiledevice3/services/mobilebackup2.py
init_mobile_backup_factory_info
async
¶
Build the Info.plist dictionary describing the device for a new backup.
Collects device identity values, the list of installed user apps (with their SINF and iTunes metadata where available), and the iTunes control files needed to make the backup restorable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
afc
|
AfcService
|
An open AFC service used to read the device's iTunes control files. |
required |
Returns:
| Type | Description |
|---|---|
|
The assembled Info.plist contents as a dictionary. |
Source code in pymobiledevice3/services/mobilebackup2.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | |
resolve_backup_selection
staticmethod
¶
Map preset selection names (e.g. "sms", "contacts") to their BackupSelectionRule sets.
Names are matched case-insensitively against the built-in BACKUP_SELECTIONS presets.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only
|
Optional[Sequence[str]]
|
Selection names to resolve. If None or empty, no selections are resolved. |
required |
Returns:
| Type | Description |
|---|---|
tuple[BackupSelectionRule, ...]
|
The combined rules for all resolved names, or an empty tuple if |
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
If a name is not a known preset; the message lists the invalid name and all available presets. |
Source code in pymobiledevice3/services/mobilebackup2.py
should_preserve_backup_file
staticmethod
¶
should_preserve_backup_file(file_name: str, device_name: str, filter_callback: Optional[BackupFilterCallback]) -> bool
Decide whether a backup file should be preserved.
Known backup metadata files (BACKUP_METADATA_FILES) are always preserved. With no
filter callback every file is preserved; otherwise the callback decides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name
|
str
|
The file name (with or without path) to evaluate. |
required |
device_name
|
str
|
The device-side name associated with the backup file. |
required |
filter_callback
|
Optional[BackupFilterCallback]
|
Optional predicate taking a |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the file should be preserved, False otherwise. |
Source code in pymobiledevice3/services/mobilebackup2.py
selection_filter_callback
classmethod
¶
Build a filter callback that keeps files matching any of the given selection rules.
The returned callback matches device-name entries via BackupSelectionRule.matches_device_name
and manifest entries via BackupSelectionRule.matches_manifest_entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rules
|
Sequence[BackupSelectionRule]
|
The |
required |
Returns:
| Type | Description |
|---|---|
BackupFilterCallback
|
A |
Source code in pymobiledevice3/services/mobilebackup2.py
regex_filter_callback
staticmethod
¶
Build a filter callback that keeps files whose path matches any of the given regexes.
Patterns are searched (not fully matched) against the file's device name and against its domain/relative-path combinations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
patterns
|
Sequence[str]
|
Regular expression patterns used to match backup files. |
required |
Returns:
| Type | Description |
|---|---|
BackupFilterCallback
|
A |
Source code in pymobiledevice3/services/mobilebackup2.py
combine_filter_callbacks
staticmethod
¶
combine_filter_callbacks(*callbacks: Optional[BackupFilterCallback]) -> Optional[BackupFilterCallback]
Combine several filter callbacks into one that keeps a file if any of them keeps it.
None entries are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callbacks
|
Optional[BackupFilterCallback]
|
Optional |
()
|
Returns:
| Type | Description |
|---|---|
Optional[BackupFilterCallback]
|
A combined |
Source code in pymobiledevice3/services/mobilebackup2.py
prune_backup_directory
classmethod
¶
prune_backup_directory(device_directory: Path, filter_callback: Optional[BackupFilterCallback], password: str = '') -> None
Delete on-disk backup files rejected by the filter, keeping metadata and allowed files.
First prunes the manifest to the set of allowed file IDs, then removes any stored files (and now-empty hash-prefix directories) not in that set. Backup metadata files are always kept.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_directory
|
Path
|
Path of the per-device backup directory to prune. |
required |
filter_callback
|
Optional[BackupFilterCallback]
|
Predicate selecting which files to keep; if None, nothing is pruned. |
required |
password
|
str
|
Backup password; required when the backup is encrypted. |
''
|
Source code in pymobiledevice3/services/mobilebackup2.py
prune_backup_manifest
classmethod
¶
prune_backup_manifest(device_directory: Path, filter_callback: Optional[BackupFilterCallback], password: str = '') -> set[str]
Prune Manifest.db to the files the filter keeps and return their file IDs.
For encrypted backups the manifest is transparently decrypted, pruned, and re-encrypted in place using the password-derived key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_directory
|
Path
|
Path of the per-device backup directory. |
required |
filter_callback
|
Optional[BackupFilterCallback]
|
Predicate selecting which files to keep; if None, nothing is kept. |
required |
password
|
str
|
Backup password; required when the backup is encrypted. |
''
|
Returns:
| Type | Description |
|---|---|
set[str]
|
The set of file IDs that were kept. |
Raises:
| Type | Description |
|---|---|
BackupFilterPasswordRequiredError
|
If the backup is encrypted and no password is given. |
Source code in pymobiledevice3/services/mobilebackup2.py
device_link
async
¶
device_link(backup_directory, filter_callback: Optional[BackupFilterCallback] = None, password: str = '')
Async context manager yielding a connected DeviceLink for backup operations.
Performs the device-link and mobilebackup2 version exchanges on entry and disconnects on exit. The given filter callback governs which incoming files are written to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backup_directory
|
Directory the device link reads from and writes to. |
required | |
filter_callback
|
Optional[BackupFilterCallback]
|
Optional predicate controlling which files are preserved. |
None
|
password
|
str
|
Backup password (unused here directly; passed through by callers). |
''
|
Source code in pymobiledevice3/services/mobilebackup2.py
pymobiledevice3.services.dtfetchsymbols.DtFetchSymbols ¶
Client for the com.apple.dt.fetchsymbols developer service.
Lists and downloads the device's shared cache (DSC) symbol files, used by debuggers to symbolicate addresses without a copy of the device's binaries on the host. A fresh lockdown developer service connection is opened for each command.
Source code in pymobiledevice3/services/dtfetchsymbols.py
list_files
async
¶
List the symbol files available on the device.
Returns:
| Type | Description |
|---|---|
list[str]
|
File names, indexed in the same order the index passed to |
Source code in pymobiledevice3/services/dtfetchsymbols.py
get_file
async
¶
Download a single symbol file and write it into the given stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fileno
|
int
|
Index of the file to fetch, as returned by |
required |
stream
|
IO
|
Writable binary stream the file contents are written to in chunks. |
required |
max_bytes
|
Optional[int]
|
Optional cap on the number of bytes to read; when None the whole file is downloaded. |
None
|
Source code in pymobiledevice3/services/dtfetchsymbols.py
pymobiledevice3.services.remote_fetch_symbols.RemoteFetchSymbolsService ¶
Bases: RemoteService
Client for the com.apple.dt.remoteFetchSymbols RemoteXPC service (RSD/CoreDevice).
Lists the device's dyld shared cache (DSC) files and downloads them to the host,
preserving their on-device directory layout. Downloads run concurrently across up to
MAX_CONCURRENT_DOWNLOADS workers.
Inherits async context manager support from RemoteService; use within an
async with block to manage the underlying connection.
Source code in pymobiledevice3/services/remote_fetch_symbols.py
get_dsc_file_list
async
¶
Query the device for the list of available DSC files.
Returns:
| Type | Description |
|---|---|
list[DSCFile]
|
One |
Source code in pymobiledevice3/services/remote_fetch_symbols.py
download
async
¶
Download all DSC files into a local directory, reproducing their device paths.
Each file is written under out at its device-relative path (the leading "/" is
stripped), and progress is shown via a tqdm bar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out
|
Path
|
Destination directory; intermediate parent directories are created as needed. |
required |
Source code in pymobiledevice3/services/remote_fetch_symbols.py
pymobiledevice3.services.simulate_location.DtSimulateLocation ¶
Bases: LockdownService, LocationSimulationBase
Client for the com.apple.dt.simulatelocation developer service.
Overrides the device's reported GPS location with a fixed coordinate, or clears any previously set override. A fresh lockdown developer service connection is opened for each command.
Source code in pymobiledevice3/services/simulate_location.py
clear
async
¶
Stop simulating a location and restore the device's real location.
Source code in pymobiledevice3/services/simulate_location.py
set
async
¶
Start simulating the given location.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latitude
|
float
|
Latitude in decimal degrees. |
required |
longitude
|
float
|
Longitude in decimal degrees. |
required |