How can I restore iBooks stored in iCloud from a Time Machine backup?
I found this was possible use the command line tmutil.

First, I checked that the files were in my backup:

$ tmutil listbackups | tail -n 3
/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-123506
/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-212807
/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-224355


Check the iBooks folder was backed up

$ ls '/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-224355/Macintosh HD/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks'
Data            Documents       metadata.nosync
$ ls '/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-224355/Macintosh HD/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks/Documents' | wc -l
402
$ ls '/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-224355/Macintosh HD/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks/Documents' | tail -n 3
ruby.epub
wp169en.pdf
wp196en.pdf


Restore to a temporary folder:

$ mkdir /tmp/ibooks/
$ tmutil restore '/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-224355/Macintosh HD/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks' /tmp/ibooks/
Total copied: 1518.18 MB (1591923972 bytes)
Items copied: 10006


I then made sure iBooks.app was closed (and on iOS devices too) and synchronised the restored files into the right place:

$ cd /tmp/ibooks/
$ rsync -av ./ '/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks/'
building file list ... done
[...]
sent 1539459615 bytes  received 196218 bytes  19366740.04 bytes/sec
total size is 1591923972  speedup is 1.03


I then opened iBooks.app and my books were back! iBooks spent 30 mins or so uploading to iCloud, and the books are also once again available on my iCloud devices.

Note, I attempted to directly restore from the backup to the target directory, but it failed, hence use of the temp directory and rsync.

$ tmutil restore '/Volumes/Time Machine Backups/Backups.backupdb/macbook/2017-12-31-224355/Macintosh HD/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks' '/Users/USERNAME/Library/Mobile Documents/'
/Users/USERNAME/Library/Mobile Documents/iCloud~com~apple~iBooks: The operation couldn’t be completed. File exists (error 17)