brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: tmutil startbackup --block runs a Time Machine backup and waits until it is done

Backup
~/tips/tip-macos-tmutil-startbackup-block

tmutil startbackup --auto --block

Starts a Time Machine backup from Terminal and waits until it has finished.

Back Up Now in the menu bar is fine when you’re sitting at the Mac. When I want a fresh backup as the first step of a script, right before a big cleanup or a round of upgrades, I’d rather have a command that starts the backup and only gives the prompt back once it’s finished. That’s what tmutil startbackup with --block does.

On its own, tmutil startbackup is the same as choosing Back Up Now from the Time Machine menu: it starts a normal backup if one isn’t already running, and your prompt returns straight away. Add --block and it waits for the backup to finish before it exits.

tmutil startbackup --auto --block

The --auto flag runs the backup in a mode similar to the backups macOS schedules by itself. Apple’s man page is careful about that: close to a scheduled backup, but not identical. If you have more than one backup disk, --rotation lets Time Machine rotate between them as it normally would, and --destination with an ID from tmutil destinationinfo sends this one backup to a specific disk.

Where it really pays off is in front of something you might regret:

tmutil startbackup --block && brew upgrade

The && only lets brew upgrade run when tmutil exits with 0, which the man page says it does on success in most situations. Changed your mind halfway? tmutil stopbackup cancels a backup that’s in progress.

One caveat: with --block your terminal is busy for as long as the backup takes. A small hourly increment is quick, but the first backup to a new disk or a backup after you moved a lot of files around can take a long time, so don’t put this in a script you expect to finish in seconds.

Further reading: tmutil man page (SS64 mirror)

More Backup tips restic snapshots --group-by host,paths mysqldump --routines --events mydb > mydb.sql rsync -a --files-from=list.txt /home/me/ backup:/backup/ restic find "*.txt" restic stats All Backup tips (45) All topics

Link