Qualified: (a) meeting the proper standards and requirements and training for a task; (b) limited or restricted; not absolute. Learning Linux, Investments, and Life, from someone marginally qualified in each.

Tuesday, June 20, 2006

Sharing Your Files Without Sharing All of Your Files

I keep my music backed up on a linux computer running an Apache server. My roommates and a few friends have logins to that server, so that they can download my music onto their computers if they wish. But I have purchased some of my music through iTunes, and because I can only have that music authorized on a handful of computers. So while I do want to back it up, I do not want to share it with anyone.

My solution has been to backup all my music onto the backup/share server, but then change permissions to deny access to those files I do not want to share. I accomplish this by logging onto the linux server through a terminal and issuing the following command:
find /home/share/music/ -name '*.m4p' -exec chmod -v 700 '{}' \;
This command finds all files in directory /home/share/music on the backup server that have the file extension "m4p" (the iTunes protected files). Then it passes all these files to chmod, which changes their permissions to 700 (I can do anything I want with them, but nobody else can do anything with them).

Sync and Backup with Rsync

Storage is cheap; time is not. Fortunately, the best backup tool around is free; Rsync.

If you have a mac or linux computer, or one of each, rsync offers a very flexible way of transferring files between them. I like to keep my music on my Mac computer, for ease of use around home, but I also like to mirror the music collection on a linux computer, both for backing up and for making available to myself when I travel, via a server. Rsync makes mirroring my music collection very easy. I open a terminal window and enter the following command:
rsync -avz --delete '/Volumes/unix_2/iTunes/iTunes Music/' ryan@192.168.0.100:/home/share/music
Let's decompose this command (note it would all be on the same line).

rsync
The command.

-avz
Tells rsync to copy files in archive mode, preserving directories and permissions, verbose mode to show all changes made, and compress (z) files to make the transfer faster.

--delete
Tells rsync to delete any files at the destination that have been deleted in the source destination.

'/Volumes/unix_2/iTunes/iTunes Music/'
The source of my music. the single quotes are only necessary because of the space in the "iTunes Music" folder.

ryan@192.168.0.100
My login name is "ryan" on the destination computer located at 192.168.0.100. I discovered that computer's internal IP address by running the command "ifconfig" on it.

:
You need this between the computer's IP address and the directory destination.

/home/share/music
The destination of the music on the backup/server computer. Note that there is no trailing "/".