Backup files belonged to a different uid and gid

I had Time Machine running fine. Then I bought a new hard disk and took the old one out of my Mac, replacing it with the new one and completely re-installing the OS from scratch. Snow Leopard cleverly let me continue to add backups from the new OS install to those backups I'd previously made with the old OS install.

The problem is that this has resulted in a lot of redundancy as well. Lots of files have been backed up again because of their new location on the new OS installation.

To resolve this I want to go into the existing backup and remove files from my old OS backup that have been backed up again in the new OS backup.

The problem is that when I enter TimeMachine/Finder, I am not able to see those files because they belong to a different uid/gid than my current user on my new OS installation. Therefore I am denied access from browsing folders like <user>\Desktop within the old OS backup file system in TimeMachine/Finder.

I have found an awkward solution - it's possible to launch Finder as root, then enter Time Machine from there. Then I can see the files. But a much better solution would be to somehow change the ownership of all those backed up files from the old uid to my current uid. I experimented from the command line using chown, but I'm not permitted to change the owner of these backed up files. I think it's a combination of the ACL or the Time Machine extended attributes that block me (even as root).

I'm also a bit hesitant about modifying Time Machine backup files in this way.

I hope that was clear! Obviously a fairly complicated scenario and I've searched for help for a long time already. Does anyone have any advice/solution? Thank you.


PS The 'run Finder/Time Machine as root' solution is not really enough for me either. I actually want to use 'Back in Time 2' which can show me files that came and went over time in my backup, whereas Time Machine requires me to look at every single date, looking for files that get backed up then removed. But BIT2 isn't successful at modifying these files, even when run as root. In short, the root workaround doesn't work for the more powerful BIT2 - only for Time Machine which isn't enough for me.

iMac, Mac OS X (10.6.5)

Posted on Nov 17, 2010 9:01 PM

Reply
6 replies

Nov 18, 2010 8:16 AM in response to univ0298

univ0298 wrote:
I had Time Machine running fine. Then I bought a new hard disk and took the old one out of my Mac, replacing it with the new one and completely re-installing the OS from scratch. Snow Leopard cleverly let me continue to add backups from the new OS install to those backups I'd previously made with the old OS install.


It sounds like you set up a new user account. That's the cause of the problem. 😟

The best, easiest, fastest, and most reliable thing to have done was to restore your entire system from the backups, per #14 in [Time Machine - Frequently Asked Questions|http://web.me.com/pondini/Time_Machine/FAQ.html] (or use the link in *User Tips* at the top of this forum).

As noted there, that does result in a new full backup, just as with your procedure. The difference, of course, is the user accounts now on your Mac would be recognized as the same ones on the backups.

I'm also a bit hesitant about modifying Time Machine backup files in this way.


Good! That can hopelessly corrupt them. I don't know how it's done, but it's my understanding that permissions are stored separately, so the actual backups can have special "deny everybody everything" permissions to keep us mere mortals from messing about and corrupting them.

And most of what you're looking at aren't really files and folders anyway; they're hard links.

If you hadn't made a lot of changes since the swap, you could delete the recent backups (per #12 in the FAQ), and do a full system restore from the last backup of the old drive.

Assuming you've made a lot of changes since then, though, I don't think there's much you can do without a very good chance of corrupting the backups beyond repair. There used to be a "guru" on both Time Machine and permissions posting here, who might have been able to solve this, but he's been MIA for several months.

Nov 18, 2010 9:44 AM in response to Pondini

Thanks for the reply. I intentionally did not restore from my backup - I took this as an opportunity to start from scratch again, restructuring my user logins, file system, generally cleaning everything up. So I definitely don't want to restore from the original backup, but I do still want to be able to work with those files in the backup that belonged to the previous user (uid).



In terms of the backup files, I'm aware of how the files and hard links work, and am partially aware of the extended attributes and ACLs that are defined on the files. But I don't understand them well enough to be able to get around them. I see ACL entries that basically deny everyone from touching the files, but I'm surprised that even as root user I cannot modify those ACLs. The best I've managed is to remove the ACLs (chmod -N) and then I can change owner on them. But this also strips the time machine extended attributes from the files, and so I don't think it's a good idea. What I really want to do is leave the files exactly as they were, but just change the owner from uid=502, gid=502, to 501/501.

Message was edited by: univ0298

Nov 18, 2010 9:55 AM in response to univ0298

univ0298 wrote:
Thanks for the reply. I intentionally did not restore from my backup - I took this as an opportunity to start from scratch again, restructuring my user logins, file system, generally cleaning everything up. So I definitely don't want to restore from the original backup, but I do still want to be able to work with those files in the backup that belonged to the previous user (uid).


I don't think you can do that by changing the backup files. I certainly don't know how, and I seem to recall the "guru" I mentioned saying he'd not found a way, either.

Do you have a 502 UID? Can you make or manipulate a user account, rather than the backup files?

Somebody in the UNIX forum might have a clue.

Nov 18, 2010 10:02 AM in response to Pondini

That's exactly what I'm mid-way through trying - creating a new user, and a new group, setting them to uid/gid 502/502, and then I'll login as that user and try Time Machine and (more importantly for me) Back In Time 2.

Note that as I said right at the beginning - I can launch Finder as root and then Time Machine is able to work with these files. But Time Machine is too basic an interface - specifically it won't tell you about the 10Gb files it backup up one night and then deleted the week after - you have to scroll through every directory of every backup date/time to find those.

Nov 20, 2010 4:02 AM in response to univ0298

In case anyone else ever encounters this, here's some solutions I figured out...

First you need to find out who owns the files in the backup (specifically which uid and gid - not the username and groupname names). You can do this by browsing your backup, finding the directory you don't have access to, and doing 'ls -la'. For example maybe the directory is your old user's Library folder, so with commands like this:

cd "/Volumes/Backup of My Computer/Backups.backupdb/My-iMac/2008-03-17-073717/MyHD/Users/Richard"
ls -la

you might see some entries that look like this one
drwx------+ 33 502 502 1190 Mar 14 2008 Library

(note that I looked in a backup from Mar 17 2008, but you'll need to specifically look at one example in your own backup where you're not able to view the files because of an old uid/gid).

In the above listing example for Library, the first 502 is the uid, and the second one is the gid. Both are 502 in my case.

You can also do
ls -alOe

to see the ACLs:
drwx------+ 33 502 502 - 1190 Mar 14 2008 Library
0: group:everyone deny add file,delete,add_subdirectory,deletechild,writeattr,writeextattr,chown

Note that the ACL entry 0: is the one that is stopping you doing anything (even a chown while the root user or the file owner)

So what to do?

Well there are two choices - one is easy and probably safe but a bit awkward to work with. The other is harder, riskier, but ultimately better because it's easier to work with once completed.

1) Create a user and group on your system with the right uid and gid, then login as that user if you need to run Time Machine, Back-in-Time 2, etc to access the files that your main user cannot access.

or

2) Create a temporary user and group on your system with the right uid and gid. Then use this user to change the owner of all the backup files to your main user. From then on your new user can work with them.

You can create users and groups through system preferences , Accounts, Add. After creating a new user a group you can then set the uid and gid on these to be exactly what you need by control-clicking them in the accounts entry and going to advanced.


Option 1 - Once you have the new uid and gid created, you can log out and log in with this user, then work in Time Machine (or other) to work with those backups (which your new uid/gid should be able to access).

Option 2 - If you want to tackle option 2, PLEASE BE AWARE OF THE RISKS, and I advise that you understand these steps so you can adjust them for yourself - rather than just trying to copy the commands I used. You should make backups, and don't blame me if you do damage please.

First, you need to open Terminal. Then you need to run as the temp user to make the changes of the files so that they are owned by your new installation's users. Then you need to temporarily add an ACL entry to all files so the owner can be changed, then do the owner change, then remove that temporary ACL entry.

Here is the sequence of commands, and some info on what it does:

su temp
(to run as the temp user you created with the uid needed)
id
(to check you are the uid that you need)
cd "/Volumes/Backup of My Computer/Backups.backupdb/My-iMac/"
(change to the top level of the backup structure)
chmod -R +a# 0 "group:everyone allow chown,writeattr,writeextattr" ./*/MyHD/Users/Richard/Library
(this inserts an ACL at position 0 for all backup dates (the *), and all files in the Library directory)
sudo chown -R richard:staff ./*/MyHD/Users/Richard/Library
(this recursively changes the owner to your new user and group - in my example richard:staff. You can do an ls -la to check that the files now belong to richard:staff, or whatever your main user's name and group are)
sudo chmod -R -a "group:everyone allow chown,writeattr,writeextattr" ./*/MyHD/Users/Richard/Library
(removes the ACL entries you temporarily needed in order to do the owner change)

You should now be done! The files are now owned by your new user, and thus that user can work with them in Time Machine, Back-in-Time 2, etc. from this point forwards. You could even remove the temp user and group from the system at this stage.

Note: I encountered memory errors if trying to do recursive chmod on too many files at the same time. To work around this, I had to change the * to something like 2008* which would only change the 2008 files (I'd then have to run the command again with 2009*, then 2010* etc). I also found that if I'd encountered an out of memory error, I needed to run the command to remove the ACLs first, before re-trying (with a narrower wildcard)

Message was edited by: univ0298

Jan 8, 2011 6:04 PM in response to univ0298

Hi,

Have same problem here trying to change 501,501 to 502,502.

I have no access to my 2009 backups

I'd followed through these steps:

1)sudo su root and then sudo 501username

2) cd /Volumes/TimeMachineHD/Backups.backupdb

3)Changed the chmod comand line and it worked with this sintax:
chmod -R +a# 0 "group:everyone allow chown,writeattr,writeextattr" ./ /2009/MyHD/Users/Richard/Library


4) sudo chown -R 502:502 ./ /2009/Macintosh\ HD/Library
This step failed even using root or my 502 user
I've got error "Operation not permitted" for all files

Probably this fix will not work for 10.6.* versions of MacosX

Anyway thanks

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Backup files belonged to a different uid and gid

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.