5

How can I restore a single file from an old Time Machine backup using only the Command Line Interface?

I took a snapshot of my MacOS system using Time Machine some time ago, and I'd like to restore just one file from it.

Also, I don't have GUI access to this box; only ssh (with root privilege).

Is it possible to restore just one file from a Time Machine backup using the CLI over SSH? If so, how?

0

2 Answers 2

5

You can browse to the files directly and restore them with the rsync command.

Determine path to Backups

First, list all of your existing backups using tmutil listbackups

user@host ~ % tmutil listbackups
/Volumes/externalBackups/Backups.backupdb/host/2020-06-17-095312
/Volumes/externalBackups/Backups.backupdb/host/2020-06-18-222034
/Volumes/externalBackups/Backups.backupdb/host/2020-06-21-110109
user@host ~ %

Enter Backup Directory

Next, cd into one of the above directories (the one from which you want to restore)

user@host ~ % cd /Volumes/externalBackups/Backups.backupdb/host/2020-06-21-110109
user@host 2020-06-21-110109 % 

Enter Backup's Data Directory

There should be a - Data directory with the data from this particular Time Machine backup. In this case, our backups were created with tmutil startbackup, so the Data Directory is Untitled - Data

user@host 2020-06-21-110109 % ls | grep -i Data
Untitled - Data
user@host 2020-06-21-110109 % 

user@host 2020-06-21-110109 % cd "Untitled - Data"
user@host Untitled - Data % 

Restore with rsync

You can restore a given file with rsync. For example, to restore the /private/etc/resolv.conf file to your system, you can now execute the following

user@host Untitled - Data % sudo rsync -av --progress private/etc/resolv.conf /private/etc/resolv.conf
...
user@host Untitled - Data % 
7
  • 2
    Personally I prefer using rsync rather than cp. However, since the intention is to use the cp command to restore a file from a "backup", I would recommend using cp -p. This way the restored file preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions.
    – wch1zpink
    Jun 14 at 20:44
  • Yes to the above, and ideally rsync -a for the same reason @wch1zpink mentioned.
    – Scot
    Jun 14 at 22:03
  • changed to rsync. I also prefer it, but I wasn't sure if it was installed by default in MacOS. Jun 15 at 9:19
  • ls *[dD]ata* might be more elegant than using grep. You can even make a (not actually very bold) assumption and just type cd *[dD]ata*.
    – nohillside
    Jun 15 at 9:25
  • Also, did you run sudo -s at the beginning? The cp/rsync at the end most likely will fail for non-root users (depends on the file to be copied of course).
    – nohillside
    Jun 15 at 9:27
0

If you find a GUI easier to navigate, you should be able to use an FTP client (Transmit, Filezilla, Cyberduck, etc.) and connect to your Time Machine backup via sftp.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .