A couple rsync problems

A couple days ago I decided to move my podcast management to my desktop from my macbook pro. Since I’m running an SSD, I don’t have much space on the mac to store 80+ GBs of podcasts. So after rsyncing my current list and then painstakingly resubscribing to all of my podcasts in iTunes and adding the existing episodes, I decided to try to back them up using rsync again to my FreeNAS box.

Unfortunately, since I first tried to duplicate the command on Windows (even though I knew the file permissions would not map from Windows to Unix), the permissions of my main share folder were changed to 0000. Naturally, these are useless permissions for a network share. They also prevented the rsync backup from working on my mac.

Once I discovered the changed permissions, all that was necessary to fix the problem with my mac was to restore them using chmod. Then I turned to Windows to fix the permission settings.

I removed the ‘archive’ option from the command and replaced it with just recursive directories and preserve modification times (-rt). This fixed the problem and allowed rsync to successfully copy over all of the new podcasts. To be sure I decided to check the permissions on the new files. I was surprised to see that they were set to 0000. So I turned to the Internet to find how to make rsync set permissions.

Luckily it didn’t take long and I found this post on superuser. The answer is to add a switch to rsync to tell it to change the permissions. According to the poster, adding “–chmod=ugo=rwX” to the rsync command will tell the receiver to make the new files using the filemask. This created the new files with the expected permissions of 0644 as all of the other podcast episodes have been.

Lastly, since I had already copied over eight or so podcast episodes with bad permissions I decided to fix them. I knew it would be quite a bit of work to type out the file names of all of them or to go to each folder to find them and change them so I decided to see if you could find files by permissions. Thankfully the find command is capable of doing this using the “-perm” switch. Combing this with xargs and chmod, I had a one-liner that would find the files with broken permissions and change them to the proper ones.

$ find Podcasts -perm ugo=-rwx -print0 | xargs -0 chmod 644
This entry was posted in Rsync, Terminal / Command Line. Bookmark the permalink.