I ended up writing a script that cancels Time Machine's operation when it goes into the "cleaning up" phase. The content is as follows:
#!/usr/local/bin/fish
while test 0=0
if tmutil status | grep -q "BackupPhase = ThinningPostBackup"
tmutil status
tmutil stopbackup
else
sleep 10
end
end
Note that this script will also prevent Time Machine from cleaning incomplete backups. To clean those, first run fsck_hfs -dfy
twice, the second time rebuilding the b-trees (-Race
). Then move the <***.inProgress> folder to trash using /System/Library/Extensions/TMSafetyNet.kext/Contents/helpers/bypass mv <***.inProgress folder> </volumes/drive name/.Trashes/UID/
. Then, empty the trash using Finder, because only Finder can deal with deleting hard-linked directories. (Backup the trash on your startup and other connected disk first if you don't want to delete those). Then, run fsck_hfs dfy
again, and you're done.
Note: this procedure (mainly the fsck_hfs
ones) only applies to TM sparsebundles on network drive. Network errors can cause small filesystem errors which can build up eventually. So regular fsck
is important to prevent big filesystem errors, especially when you're doing something which involves a lot of filesystem modification (like deleting a ton of directory hard-links here).
Alternatively, you can also use Carbon Copy Cloner, and if you set a long time for safety net APFS snapshots, a long and more detailed period of history will be preserved.