We need to make our life easier by creating consistency for every machine. What this means is every machine you try to use, whether it be yours or your colleagues, the environment will be the same when you sit down to help them with something. This is very important if you’re a Development Manager and you’re trying to help one of your staff.
This is one of several posts in regards to this subject.
OK, this week we’re going to sync up our directories. There are two directories that we care about (actually 3 if you count the “NetBeansProjects” directory separately).
On our Windows machine, we’re already done. We mapped in a previous post the “\\snake\developers$” directory to our Q: drive. This is where our third party libraries will be stored on Windows. We also have the “My Documents” directory that resides on our Windows file server and under that directory is the “NetBeansProjects” directory. So we’re set on the Windows side of things.
On the Apple Macintosh though, it’s not that easy. We need to use a utility called rsync to sync up our Libraries directory from the file server. The way that we do that is to first set up a rsync directory for our rsync scripts. We do this by starting up a terminal window which will start in the ${HOME} directory and execute the command “mkdir rsync” like so:
Clik here to view.

mkdir rsync
Now I’m going to create a script in that directory so I cd into it and using vi create a file called “syncLibrary.sh” like so:
Clik here to view.

vi syncLibrary.sh
We’re going to do a couple of things here. The first thing we’re going to do is mount our Windows file server “snake”. That is done using the mount command like so:
mount -t smbfs //thcampbell:<mypassword>@snake.mydomain.com:/Departments /nfs/Departments
This command will mount, using the smb protocol, the “Departments” directory on the Windows file server “snake.mydomain.com” using my username “thcampbell” and my password “<mypassword>”. It will mount that at the “/nfs/Departments” mount point on my Apple Macintosh. The “Departments” directory on snake.mydomain.com is a file shared created by my Windows Administrator.
Ok, after that’s done, I want to do my rsync. Here’s my rsync command:
rsync -auv –delete /nfs/Departments/IT/Developers/ /NetBeansLibraries
This executes the rsync command with the options “-auv” and “-delete” while will sync the files from the directory “/nfs/Departments/IT/Developers” to the “/NetBeansLibraries” directory that we created in a previous post.
I’m not going to go into options “-auv” and “-delete” in detail but basically what’s going on is that the directory “/NetBeansLibraries” will be an exact duplicate of the “/nfs/Departments/IT/Developers” directory. It will delete files and make changes to the “/NetBeansLibraries” directory each time you run it; so don’t make changes to the “/NetBeansLibrary” directory. If a change needs to be made, make it in the “/nfs/Departments/IT/Developers” directory and then run your script “syncLibrary.sh”.
So after the rsync is done we have to umount our mount point by doing the following:
umount /nfs/Departments
Ok, so here’s what we have in our file:
Clik here to view.

syncLibrary.sh
Save it! And set the permissions on it to be an executable using
chmod 755 syncLibrary.sh
and run it
./syncLibrary.sh
Clik here to view.

Execute syncLibrary.sh
Depending on how many changes you have to your Libraries directory this could take a while to run. I store other things in the “/NetBeansLibraries” directory such as Software that I need (like tomcat) and some Documentation, and you can do this too if you’d like. My third party libraries are in a sub directory called Libraries and you’ll see me reference it when I talk about managing Libraries in a later post.
But we’re not done yet. We have another couple of directories we want to sync.
We have to rsync the “${HOME}/NetBeansProjects” directory. This directory is where we store our projects and we’ll want to rsync it to the Windows file server so that a) we have access to it from our Windows machine and b) even though we’ll be using Subversion, it never hurts to have a backup of our projects.
We do pretty much the same thing as we did above. We are going to edit a file using vi called “syncNetBeans.sh”.
In this file, we first mount “snake” but this time we’re mounting the “Home” directory instead of the “Departments” directory. We’ll be mounting this directory at “/nfs/Home” on our Apple Macintosh. Again, the “Home” directory on snake, is a share that our Windows Administrator set up for us:
mount -t smbfs //thcampbell:<mypassword>@snake.mydomain.com:/Home /nfs/Home
Next we’re going to rsync our “${HOME}/NetBeansProjects” directory to “/nfs/Home/My Documents/”. This directory “/nfs/Home/My Documents” will correspond to the “My Documents” directory on our Windows machine so that when we use that machine, we’ll have access to our files without any effort.
rsync -auv –delete /Users/thcampbell/NetBeansProjects /nfs/home/thcampbell/My\ Documents
And just like before, we’re going to umount snake:
umount /nfs/Home
This is our finished file.
Clik here to view.

syncNetBeans.sh
It’s important to note that we’re syncing to snake in this script instead of from snake like we did in the previous script.
Just like before, save it, chmod it and execute it.
Clik here to view.

Execute syncNetBeans.sh
Finally I have one more directory that I want to sync. As I’m using my Apple Macintosh as my master computer, I want to edit my files in my “${HOME}/Documents” directory but have them show up in my “My Documents” directory on my Windows machine. So, we edit a file called “syncHome.sh” using vi.
Just like in the previous script, we mount “/Home” on snake to our “/nfs/Home”:
mount -t smbfs //thcampbell:<mypassword>@snake.mydomain.com:/Home /nfs/Home
Our rsync command is a little different this time though:
rsync -auv –delete –exclude=NetBeansProjects /Users/thcampbell/Documents/ /nfs/home/thcampbell
This time you’ll notice a –exclude=NetBeansProjects. What this tells rsync is that it should not do anything with the “NetBeansProjects” directory. We manage this directory using the script up above so we don’t want to mess with it here.
Then, just like before we umount snake:
umount /nfs/Home
Here’s what our finished script looks like
Clik here to view.

syncHome.sh
Save it, chmod it and run it!
Clik here to view.

Execute syncHome.sh
Now that you have your scripts created, you can run them by hand or you could run them using a cron job. It’s up to you but I’ll leave figuring out how to set up cron to you.
Image may be NSFW.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
