Transfering file and folder permissions to a clean install with rsync?
I'm periodically backing up my Mac user-folder to a remote machine by running rsync with a cron job on my machine. I'm thinking that anything useful will be in the user-folder and I can always reinstall the missing software with homebrew, so no use backing up anything else.
My backup command looks something like this:
rsync -av --delete /Users/oxprox_1/ -e "$SSH_OPTS" remote_machine:/backups/oxprox_1/
Now I recently had to replace my hard drive and do a clean install of a new OS. It was the first time I had to rsync my whole user-folder back. During the OS install I changed my username so the user folder on my machine is now named differently and I guess this UID number is also different even if the name had been the same (or is it?). If I remember correctly, I ran something like this on my machine to pull my files back:
sudo rsync -av remote_machine:/backups/oxprox_1/ -e "$SSH_OPTS" /Users/oxprox_2/
I think I used sudo
because it wouldn't modify files without it. If I remember correctly I had some issues with the permissions of my files and I managed to figure it out somehow, maybe by manually changing all the permissions, but I have been having some weird problems and issues after that.
Now I'm planning to do a new clean install and pull my old backups again, as I have not been updating the files on the remote machine after the hard drive change. So how should I do this to get the permissions correctly when returning files on my clean install, even though the username is different? I guess it should transfer all the permissions to the new user on the destination side. I want to transfer all the preferences and setting for the applications and not just my documents etc.
I have been reading about the rsync archieve option and I think maybe it could work if I just use -rlptDv
instead and omit the -o
option, but I'm not sure. Also what about the group permissions, I'm the only user on my computer.
Could you help me to understand how to do this properly? I have been reading answers here but I still don't understand this fully. I'm also open to suggestions if there are some better options to do the backups. I would still rather use rsync than Time Machine because it's so neat and easy to automate. Thanks!
As you have discovered Time Machine and the system migration scripts handle all the little corners where files are customized per unique account or tied into a system file or just not to be backed up. I would probably rsync
back the files into a new short name for which no user exists on the system.
Then take advantage of the system to fix permissions by creating the new user and answering yes when it sees the home folder present matching the short name of the user you are about to create.
- Delete oxprox_2 account or copy into oxprox_3
- Create the account to match the restore path
- Let the system fix permissions on the restored files
- Log in to the new account and test
Basically, delay making the account until after you’ve done the restore.