re: search

re: search — Simon Heimlicher's Homepage

In math we trust — everybody else, bring data.

Time Machine: UUID of Disk Changed

If you clone a volume that you backup with Time Machine, its UUID will change and Time Machine will no longer be able to make backups of it. However, it won’t tell you directly what the problem is. Rather, you will find entries like the following in /var/log/system.log:

backupd Backup failed with error: 12
backupd Error (12): Link of previous volume failed for macosx.

If you want to continue to backup to the same volume in your Time Machine backup database, the following script allows you to change the UUID of the existing backups, leading Time Machine to backup as if the volume’s UUID had never changed.

Note

In OS X Lion 10.7, there is a nifty new command line utility called tmutil, which takes care of the task previously accomplished by the script described below.

From its man page (man tmutil):

 associatedisk [-a] mount_point snapshot_volume
         Bind a snapshot volume directory to the specified local
         disk, thereby reconfiguring the backup history. Requires
         root privileges.

         In Mac OS X, HFS+ volumes have a persistent UUID that is
         assigned when the file system is created. Time Machine uses
         this identifier to make an association between a source vol-
         ume and a snapshot volume. Erasing the source volume creates
         a new file system on the disk, and the previous UUID is not
         retained. The new UUID causes the source volume -> snapshot
         volume assocation to be broken. If one were just erasing the
         volume and starting over, it would likely be of no real con-
         sequence, and the new UUID would not be a concern; when
         erasing a volume in order to clone another volume to it,
         recreating the association may be desired.

         A concrete example of when and how you would use
         associatedisk:

         After having problems with a volume, you decide to erase it
         and manually restore its contents from a Time Machine backup
         or copy of another nature. (I.e., not via the Mac OS X
         installer's System Restore feature or Migration Assistant.)
         On your next incremental backup, the data will be copied
         anew, as though none of it had been backed up before. Tech-
         nically, it is true that the data has not been backed up,
         given the new UUID. However, this is probably not what you
         want Time Machine to do. You would then use associatedisk to
         reconfigure the backup so it appears that this volume has
         been backed up previously:

         thermopylae:~ thoth$ sudo tmutil associatedisk [-a] "/Vol-
         umes/MyNewStuffDisk" "/Volumes/Chronoton/Backups.back-
         updb/thermopylae/Latest/MyStuff"

         The result of the above command would associate the snapshot
         volume MyStuff in the specified snapshot with the source
         volume MyNewStuffDisk. The snapshot volume would also be
         renamed to match. The -a option tells associatedisk to find
         all snapshot volumes in the same machine directory that
         match the identity of MyStuff, and then perform the associa-
         tion on all of them.

Note

Mac OS X 10.6 Snow Leopard has ACLs enabled by default and therefore ships without the fsaclctl command line tool that we need to temporarily turn off ACLs. You may try to grab it from a Leopard DVD: http://porkrind.org/missives/how-to-get-fsaclctl-off-your-leopard-install-dvd/

Use this at your own risk!

Usage Example

1
2
3
4
5
6
7
8
9
10
./timemachine-setuuid.sh "Backup of MyMac" "Macintosh HD"
	
Using Time Machine volume
  "/Volumes/Backup of MyMac"
with backup database located at
  "/Volumes/Backup of MyMac/Backups.backupdb/MyMac"
	
UUID of volume "Macintosh HD" will be set to "394FBC68-AA00-3556-81B5-D61F5BFA27ED"
	
Done

Script

And here’s the script.

timemachine-setuuid.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
set -u; set -e
	
# From: http://www.macosxhints.com/article.php?story=20090213071015789
# All credits go to the author "only_solutions ()". Their profile is at
# http://www.macosxhints.com/users.php?mode=profile&uid=1060791
	
if [[ $# -ne 2 ]]; then
    echo "Usage: `basename "$0"` `<Time Machine volume, e.g. \"Backup of My Mac\">` `<Disk whose UUID needs to be set, e.g. \"Macintosh HD\">`"
		exit 1
fi
	
errxit () {
    [[ "$2" ]] && printf "$2\n" >&2
    exit ${1:-1}
}
	
say () {
    msg="${1-`}"
    [[ ! -z "$msg" ]] && printf "$msg\n" >&2
}
	
# Check if Time Machine volume is mounted in /Volumes
TMV="$( cd "/Volumes/$1" && pwd )"
	
# Check if source volume is mounted in /Volumes
SRCVOLUME="$( cd "/Volumes/$2" && pwd )"
	
# Strip '/Volumes' to obtain source volume name
VOLNAME="${SRCVOLUME#/Volumes/}"
	
# Get source volume UUID
UUID="$( diskutil info "$SRCVOLUME" | sed -nE 's/.*Volume UUID: +([-A-F0-9]+).*/\1/p' )"
	
# Get path to backup database
BDB="$TMV/Backups.backupdb/$(scutil --get ComputerName)"
if ! ls "$BDB" &>/dev/null; then
    errxit 1 "Invalid backup database path:
  \"$BDB\""
fi
	
if ! ls "$BDB/"*/"$VOLNAME" &>/dev/null; then
    errxit 1 "Volume \"$VOLNAME\" not found in backup database at
  \"$BDB\""
fi
	
say "Using Time Machine volume
  \"$TMV\"
with backup database located at
  \"$BDB\"
	
UUID of volume \"$VOLNAME\" will be set to \"$UUID\"
"
	
# Disable ACL protection on Time Machine volume
sudo fsaclctl -p "$TMV" -d
	
sudo xattr -w com.apple.backupd.SnapshotVolumeUUID "$UUID" \
    "$BDB"/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-*/"$VOLNAME"
	
# Re-enable ACL protection on Time Machine volume
sudo fsaclctl -p "$TMV" -e
	
echo "Done"

Save the above code to a file called e.g. timemachine-setuuid.sh and make that file executable by issuing

1
chmod +x "timemachine-setuuid.sh"