Syncing files from your Mac to your Windows 7 PC with rsync
If you are like me, you have your music in more than one place because you are so scared that you are going to lose it and have to "rip all those CDs" again! I have my music on my Mac, my wife's mac on my PC, on my server and on a portable hard drive that I carry to work. I know... a bit excessive on all the home machines but it helps me sleep at night knowing my precious music library is safe. I am the same way with my pictures. Mac, PC, Server, Picasa web Albums... they are everywhere!
Having the files in all of those places locally is pretty much a guarantee that I won't lose everything all at once. But, as I'm sure you can imagine, things get pretty well out of sync very fast. I use my Mac more than most other machines so it tends to be my "master copy" of music and pics... iTunes being the gate keeper for the music. As I add more and more music to iTunes on my Mac, all of the other locations become more and more out of sync.
In the old days, I would just copy everything over to each machine (or FTP it up to my server) and manually keep things in sync. It works but where is the fun in that? These days, I just keep everything in sync with a nifty little command called 'rsync'.
As I said, my "master copy" of music is my Mac. My secondary location would be my PC, next my server, etc… When I add new music to my Mac, I can simply create an SMB share to my PC, for instance, and rsync my music over to the PC!
rsync is more than just copying files form once place to another, it will not only copy files to the target that do no already exist, if I were to delete a file on my Mac, it would also delete it on the PC. This isn't happening by deleting everything on the target and doing a full copy of course; it is an actual sync of deltas. If files are the same, nothing happens; if the file is new, deleted or changed, that is synced over.
So enough of the explaining… you can `man rsync` for all that. Here is a scenario on syncing files from a Mac to a Windows 7 Pro machine.
First, you will need to have a share setup somewhere on the windows 7 machine that you can write to remotely.
Next, just open Finder on the Mac and hit command + k to open the "Connect to Server" window. If you haven't done anything fancy with your windows share, a normal SMB connection should work fine. In the "Server Address" field of the "Connect to Server" dialog, enter smb://serverName where "servername" is either your PC's hostname or IP address. For instance, my PC's IP is 10.11.12.13 (yes really) so I enter: smb://10.11.12.13 in the Server Address field and hit Connect.
If this is the first connection you are making to the PC, you may be asked to provide credentials. Once it connects, you should be presented with a list of possible shares to connect to and mount. My share was simply called "Music". Select the desired share and you should connect to it. Finder will open a window of that share's contents.
Not only are you connected to the share now, it is mounted in /Volumes/ to make life easy. For instance, my share name was "Music" so once I am connected to smb:///10.11.12.13/Music, it is mounted locally as /Volumes/Music/
Now that we are connected, it is time to sync my local iTUnes library to my Music share. To do that, the following command is all I have to run.
rsync -avz --delete --exclude '.DS_Store' /Users/bobby/Music/iTunes/iTunes\ Music/Music/ /Volumes/Music/
So let's break that down.
'rsync' is obviously the command name.
The '-a' option is for archive mode. This basically tells rsync that you want to preserve everything about the files. It also tells it that you want recursion.
The '-v' option s just to give us more detail in the output; it stands for 'verbose'. WIthout this option, you will not be able to tell where the process is since, by default, rsync works silently.
The '-z' option enables compression. Doing this speeds up the transfer since it is obviously sending less data and then decompressing once it is on the other side.
--delete tells rsync that you want to delete files on the target that do not exist on the source.
--exclude does just as you would expect it to; it excludes files in the comma delimited list that follow it. In this case, we are just excluding the annoying .DS_Store files that live in so many Mac directories.
Next is the source directory where all files should be copied from. In my case, it was my local iTunes Music directory. "/Users/bobby/Music/iTunes/iTunes\ Music/Music/". Don't let that extra \ throw you. It is just escaping the space that follows it.
Finally, the last bit of information that rsync needs is the destination directory. In my case, it is the mounted Music directory that can be accessed through "/Volumes/Music/".
That is it! All you have to do now is run the command and let it do what it does best... sync stuff!
Obviously, you should test this out on some smaller test directories/files before you hose all of your precious data but the above does not change the source so you should be safe… just make sure there is nothing on the target that you don't want to lose that isn't on the source as well. If you are unsure, just remove the --delete option.
Now go forth and sync all that crap you have scattered everywhere!