Skip to content

Instantly share code, notes, and snippets.

@Pictor13
Created September 15, 2022 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pictor13/53c193bc0c1a922ca0bde044dc397692 to your computer and use it in GitHub Desktop.
Save Pictor13/53c193bc0c1a922ca0bde044dc397692 to your computer and use it in GitHub Desktop.
TimeMachine: 2 backup copies, on the cloud (OneDrive) and on external hard-drive.

To trick OneDrive in backing up TimeMachine's backup, we use a SparseBundle filesystem (explorable) image/file, as it supports differential upload. The partition of the SSD (that contains the backup as a file) is symlinked inside the OneDrive folder (using fstab) so its content (the sparsebundle) gets synced AND is actually stored on the SSD partition (without taking space on the machine).

Create a TimeMachine.sparsebundle first, using Disk Utility:

  • set filesystem to Journaled HFS+ - Mac OS Extended (Journaled) (NOT Case-Sensitive)
  • choose "sparse bundle" as image-format
  • use a GUID partition map
  • give name "TimeMachineMac10" (is the mounting name, it will be used below from tmutil-setdestination!) Set a passphrase with encryption.

  • Connect hard drive. This partition will automount (see below to change mount point)

  • Mount the sparse-bundle image in this directory (the sparse-bundle is encrypted with password). You'll get a new "TimeMachine" volume mounted,

  • You can't select the mounted volume directly from TimeMachine GUI. So choose the TimeMachine destination via shell with:

    sudo tmutil setdestination /Volumes/TimeMachineMac10"

  • If you need to resize the sparse-bundle

    • It won't be possible to resize the container via Disk Utility app. Do it via shell with

      hdiutil resize -size 150g "/Users/Shared/OneDrive/Backup/MacBook_TimeMachine/TimeMachineMac10.sparsebundle"

    • resize the partition with the new space available


To backup over a cloud service you can't use symlinks, since they can't be handled decently. Alternative is to mount the "MacBook backup" volume directly inside the OneDrive folder, so that it will be seen as normal file and be synced.

  • umount the drive
  • sudo vifs to edit /etc/fstab
  • add UUID=123abc "/Users/Shared/OneDrive" hfs rw 0 2 with 123abc being the UUID retrievable with "Get info" in DiskUtility.
    Beware, spaces in mount path MUST be encoded/escaped as \040 .

Example: UUID=3E5D6203-74F7-46DA-A79E-F923D5C320D2 /Users/Shared/OneDrive/Backup/MacBook_TimeMachine apfs rw 0 2


Time Machine is stupid and will store local snapshots on your machine and forget to purge them out. Also, looks like time machine considers these snapshots for backing up again, so you'll get weird problems where the requested free space on the backup drive is unreasonable. Run:

  • sudo tmutil listlocalsnapshots /
  • sudo tmutil thinLocalSnapshots / 10000000000 4 (this will thin the snapshots; 1000000000 is how many bytes to reclaim; 4 is the urgency; see the manual of tmutil)
  • sudo tmutil listlocalsnapshots /

=========

OTHER RANDOM STUFF:

Creates a sparsebundle disk image with a 250GB band size

hdiutil create -size 250g -type SPARSEBUNDLE -nospotlight \
    -volname "TimeMachineMac10" -fs "Journaled HFS+ - Mac OS Extended (Journaled)" \
    -imagekey sparse-band-size=262144 \
    -verbose -encryption -stdinpass \
    /Users/Shared/OneDrive/Backup/MacBook_TimeMachine/TimeMachineMac10.sparsebundle

Copy the plists from TIME_MACHINE_IMAGE to NEW_IMAGE TIME_MACHINE_IMAGE=your-machine-name.old.sparsebundle NEW_IMAGE=your-machine-name.sparsebundle cp $TIME_MACHINE_IMAGE/com.apple.TimeMachine.*.plist $NEW_IMAGE For motivation, see: http://sansumbrella.com/writing/2012/the-reluctant-sysadmin-nas-time-machine/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment