Adding a backup disk is a few clicks in System Settings, but when I’m setting up a Mac from a script or over SSH I’d rather do it in one line. tmutil setdestination takes a local volume or an SMB share and makes it a Time Machine destination.
For a network share the argument is a URL of the form smb://user@host/share. Two flags matter a lot here:
sudo tmutil setdestination -a -p smb://[email protected]/timemachine
-a adds the share to the list of destinations. Leave it out and tmutil replaces your current list with this one destination, which you won’t want if a USB drive is already doing backups. With more than one destination, Time Machine picks one from the list for each backup by itself.
-p asks for the password at a prompt that doesn’t echo. The man page allows you to put the password in the URL as user:pass@host, but it also points out that every argument you give a program is visible to all users on the system via ps. My advice: always use -p.
For a local disk you give the mount point instead, like /Volumes/Backup. Afterwards, tmutil destinationinfo shows whether the new destination is there.
The caveat: the share itself has to be ready for Time Machine on the server side. Apple says the NAS has to support Time Machine over SMB, so check its documentation. On Unraid that’s the SMB export setting Yes (Time Machine) on the share. The command also needs root and Full Disk Access, so run it with sudo from a terminal app that has that permission.
Further reading: tmutil man page (SS64 mirror), Backup disks you can use with Time Machine