How does Time Machine (on a High Sierra MacBook Pro with APFS) know which files in a folder have changed since the last backup? I know that TM relies on FSEvents to watch for directories with changed file(s). What I don't know is what TM does when it learns that 1+ files in a folder have changed. I'm looking for a detailed technical explanation, not high-level info about Time Machine itself. Specifically:
- What information about each file (e.g. in a folder with 1 changed files and 999 files unchanged since the last backup) does TM use to determine which files are same as the last backed-up version? Does TM look only at file size & modification time? Does it actually read file contents? Does it read file attributes?
- What filesystem API calls does Time Machine use to check which files have changed? Specifically, does it make one (or a small number) of calls per folder, e.g. to fetch a directory listing? Or will it make 1+ calls per file to pull additional info like file contents, attributes, etc.?
- If the answers to the questions above vary (e.g. "sometimes TM does XXX, sometimes YYY") then what are the reasons why TM would be making many filesystem calls for each unchanged file in a folder?
I'm asking because I'm trying to diagnose slow Time Machine incremental backups on my late-2015 MacBook Pro running High Sierra. Each "hourly" backup takes 30+ minutes to complete, even though the amount of data backed up each time is under 2GB.
Looking at logs of Time Machine disk activity (using sudo fs_usage -f filesys backupd
), the culprit seems to be filesystem access of unchanged message and attachment files associated with Outlook 2016 Mac.
Outlook creates 256 folders for messages and 256 folders for attachments, and it evenly distributes new messages and attachments among these folders. For example, my Outlook profile has about 250K messages, most of which have 1+ attachments. Each of those 512 folders contains about 1,000 messages. I get about 500 new messages per day, so if it's been a day since my last backup, each of those 512 folders will have 1-3 new files and about 1,000 unchanged files.
Looking at the file system logs, Time Machine is making many filesystem calls for each file, even though only a few hundred files have changed out of 500,000+ files in these folders. Filesystem access for each unchanged file is quick (~0.075 seconds in the example log excerpt below) but if you multiply 0.075 seconds by 500K files, that's over 10 hours! Time Machine runs multiple threads so each incremental backup doesn't take 10 hours, but instead takes 30+ minutes for each "hourly" backup.
That's a lot of battery usage and disk access to look at 500,000+ files every hour that haven't changed. Note that 30+ minutes is the TM speed after I've used sudo sysctl debug.lowpri_throttle_enabled=0
. Without this change, it's even slower.
I'm trying to figure out the root cause of the problem:
- Is it how my computer is configured? Is there a change I can make to my files, to Time Machine settings, etc. that would cause TM to stop spending so much time examining unchanged files on every incremental backup?
- Is the problem fundamental to how Outlook 2016 Mac stores it messages and attachment files, so every Mac user of Outlook with a large and active mailbox will have this problem? For example, does Outlook do something unusual with attributes that may cause TM to spend extra time examining Outlook's files compared to other apps that create lots of small files?
- Or is the root cause in the design of Time Machine, where it's expected that if any files in a folder have changed then TM will make relatively-expensive filesystem calls for each file in order to verify which files have changed?
Here's a logs sample (for a single file that hasn't been changed since the last backup) that suggest that Time Machine is doing a lot of filesystem access for each unchanged file. I count 11 (!!!) file system accesses for this one 901-byte file that is already backed up and is unchanged since the last backup.
09:14:19.783112 getattrlist .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000027 backupd.944294
09:14:19.783424 fsctl .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000006 backupd.944294
09:14:19.783428 fsctl .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000004 backupd.944294
09:14:19.783542 getattrlist .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000057 backupd.944294
09:14:19.783603 listxattr .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000016 backupd.944294
09:14:19.783612 listxattr .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000008 backupd.944294
09:14:19.805903 listxattr .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.022290 backupd.944294
09:14:19.806028 listxattr .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000109 backupd.944294
09:14:19.856232 HFS_update (__M__c__) .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000013 backupd.948297
09:14:19.856258 link .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.050019 backupd.948297
09:14:19.856394 getattrlist .Office/Outlook/Outlook 15 Profiles/2018-05-11/Data/Message Attachments/137/8969C57E-7F6D-4152-AF11-FDF535486C92.olk15MsgAttachment 0.000051 backupd.948297
I know that I can exclude Outlook folders from Time Machine backups, but I'm hesitant to do this as it might prevent me from restoring messages.
I've already tried deleting the FSEvents logs (via sudo mv /.fseventsd /.fseventsd.bak
and a reboot) and allowing them to be re-created, which sped up backups considerably so that they'll only take a few minutes if I haven't started Outlook since the last backup. But after I run Outlook, backups take 30+ mins. I've verified by looking at logs that the extra time is not due to backup data volume-- the 1.3GB Outlook.sqllite
file is backed up in 1-2 minutes each time-- but instead seems to be caused by the 100,000s of files that Time Machine is looking at but not backing up.
It's not a network issue nor a speed issue of my backup NAS drive: when TM is backing up large files, it backs up 10-30 megabytes per second over WiFi (I have fast WiFi!). Also, connecting directly to my gigabit ethernet doesn't improve speed when TM is churning through all those tiny Outlook files.
UPDATE:
As advised by Monomeeth in his answer below, I downloaded and ran Time Machine Mechanic (really helpful tool!). Here's the output for the last 12 hours.
Analysis from 2018-05-23 19:38:58 +0000 to 2018-05-24 05:38:58 +0000 for 10 hours:
Backing up to /dev/disk2s2: /Volumes/Time Machine Backups/Backups.backupdb
on which there were 411.74 GB, 411.74 GB, 411.74 GB, 411.74 GB, 411.74 GB, 411.74 GB available.
Started 6 auto backups, and 0 manual backups; completed 7 backups successfully,
last backup completed successfully 7.0 minutes ago,
backed up a total of 16417 files, range 639 to 4666 in each backup,
total data for each backup was 2.09 GB, 2.1 GB, 1.89 GB, 1.58 GB, 1.66 GB, 1.59 GB, 1.54 GB.
Times taken for each auto backup were 93.8, 37.8, 29.8, 34.4, 35.4, 87.6 minutes,
intervals between the start of each auto backup were 140.5, 70.8, 63.4, 69.9, 65.9 minutes.
Created 0 new backups, and deleted 7 old backups,
cancelled 4 backups.
7 errors reported:
2018-05-23 13:27:42.967395-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-23-113921.inProgress/B14EC326-8AE7-4C23-8F37-17BDEFCF9F1C
2018-05-23 20:33:49.535143-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-36 "ioErr: I/O error (bummers)" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-21-163447
2018-05-23 20:33:49.536821-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-22-193257
2018-05-23 20:33:49.536960-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-22-183736
2018-05-23 20:33:49.537620-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-22-150607
2018-05-23 20:33:49.537704-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-22-134626
2018-05-23 20:33:49.539118-0700 Error: Error Domain=NSOSStatusErrorDomain Code=-50 "paramErr: error in user parameter list" deleting backup: /Volumes/Time Machine Backups/Backups.backupdb/Justin’s MacBook Pro/2018-05-22-120245
Note that there's no deep scans, and each backup took a minimum of 30 minutes to back up 1.5-2 GB. Most of the size is the single 1.3GB Outlook.sqllite file, which is backed up in about 2 minutes according to the file system logs, which works out about 10 megabytes/sec. But most of the time is taken (again according to file system logs) by reading/checking 100,000's of unchanged files.
Is this normal? It seems unexpected for TM to have knowledge of what files have changed (via FSEvents) but still have to look at every file. Is there something unusual about Outlook's files that causes it to happen with Outlook's files but not with other applications' files? Could it be that Outlook is using extended attributes (e.g. "Author" and "Recipient" attributes on email message files) and those attributes are what are causing the slowdown?
I'm not sure what to make of the errors, but they're referring to deleting backups. Perhaps that's an unrelated issue to my slow backups?