<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6946864571745885149</id><updated>2011-04-21T18:01:08.696-07:00</updated><category term='Ehcache'/><category term='clustering'/><category term='task scheduler'/><category term='java'/><category term='bash'/><category term='rsync'/><category term='networking'/><category term='backup'/><title type='text'>Code Noter</title><subtitle type='html'>Notes on stuff I don't want to figure out twice.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codenoter.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://codenoter.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Woozy</name><uri>http://www.blogger.com/profile/11819073339164962416</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6946864571745885149.post-7940643286274437294</id><published>2008-11-05T09:16:00.000-08:00</published><updated>2008-11-05T13:38:03.572-08:00</updated><title type='text'>Calculating a Multicast Address for Cluster Partitioning</title><content type='html'>&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Say you want to deploy multiple instances of an application on multiple machines, all using a common data store.  Further, you want to let them all talk to maintian some sort of state.  But you also want to have development and test clusters in the same subnet environment.  One common mechanism for cluster membership announcements is IP multicast.  This is one method that can be used by &lt;/span&gt;&lt;a href="http://www.jgroups.org/"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;JGroups&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;, and is the default used by &lt;/span&gt;&lt;a href="http://ehcache.sourceforge.net/"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;EHCache&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;.&lt;/span&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;But what if you don't want to have to bother remembering to configure the same/different addresses on each node to keep your test and development clusters independent?  That is just overhead grunt work that is prone to error, and can lead to data corruption if done incorrectly.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;A simpler, automated approach is to calculate the multicast address on the fly, based on the configuration information you already have to configure by hand for the common data store.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;For example, my company uses the JDBC URL for a MySQL database, combined with a user name and password for accessing it.  These are pieces of information necessary for each application node anyway, so using them to generate the multicast address removes the need to synchronize another configuration parameter.  In the case of EHCache with Hibernate, the multicast configuration parameters would even need to be in a different file than your main application configuration.  Too messy.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;My assumption here will be that this is a cluster inside a private network, so the multicast address will come from the &lt;/span&gt;&lt;a href="http://www.cisco.com/en/US/tech/tk828/technologies_white_paper09186a00802d4643.shtml#wp1002679"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Administratively Scoped&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; address space.  &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;This technique only varies the final two segments of the IP address.  I'll use the site-local scoped range of 239.555.*.* as my starting point, but any initial two-segment value in the administrative scope will work as a base address.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;In Java, a String hash code is represented by an int, positive or negative.  The maximum positive value of an int is 2,147,483,647 (Integer.MAX_VALUE).  The address space available for site-local multicast is&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;255 * 255 * 65535 + 255 * 65535 + 65535 = 4,278,190,335 &gt; 2,147,483,647&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;segment 3               segment 2       port&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;So, taking the absolute value of a String hash (with a sanity check for Integer.MIN_VALUE, as abs(MIN_VALUE) returns MIN_VALUE - see the &lt;/span&gt;&lt;a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Math.html#abs(int)"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;JavaDoc&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;) will be a &lt;/span&gt;&lt;span class="Apple-style-span" style="font-style: italic; "&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;fairly unique&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt; value.  Hash codes aren't truely unique, of course, but if you examine the String.hashcode() implementation, you will see that no two values with anything approaching similar contents or length can return the same hash code.  So unles you choose starting String values that may be wildly different both in content and length, this value should work just fine for ensuring unique multicast addresses.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Now for the mapping math.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span"  style="  ;font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="  ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;int hash = "config-with-DBHost/Port/User/Pwd".hashcode();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: verdana; font-size: 13px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: verdana; font-size: 13px; "&gt;// hash modulo max port&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="  ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;int port = hash % 65535&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; "&gt;//hash divided by max port modulo max segment&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;int segment4 = hash / 65535 % 255&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-family: verdana; font-size: 13px; "&gt;//hash divided by max port divided by max segment&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;int segment 3 = hash / 65535 / 255&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;Put the address together like this:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;base.address.segment3.segment4&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:verdana;"&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;See how easy that was?  The key is to make sure the string you are using for your hash is the same on all nodes you want to share a given multicast address/port combination.  That means if something like database host is part of the string, make sure it isn't "localhost" on one node and a DNS name on all the others - that obviously will result in different hashes.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6946864571745885149-7940643286274437294?l=codenoter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codenoter.blogspot.com/feeds/7940643286274437294/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6946864571745885149&amp;postID=7940643286274437294' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default/7940643286274437294'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default/7940643286274437294'/><link rel='alternate' type='text/html' href='http://codenoter.blogspot.com/2008/11/calculating-multicast-address-for.html' title='Calculating a Multicast Address for Cluster Partitioning'/><author><name>Woozy</name><uri>http://www.blogger.com/profile/11819073339164962416</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6946864571745885149.post-5761434015675975732</id><published>2008-10-16T12:28:00.001-07:00</published><updated>2008-10-16T15:08:48.351-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bash'/><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='rsync'/><category scheme='http://www.blogger.com/atom/ns#' term='task scheduler'/><title type='text'>Daily Remote Backups with Rsync</title><content type='html'>&lt;span style="font-family:trebuchet ms;"&gt;There are tons of pages on the web devoted to &lt;a href="http://samba.anu.edu.au/rsync/"&gt;rsync&lt;/a&gt; scripts, but I had to pull together info from several sites to do what I wanted, so I'm adding another tutorial for a different basic use case.&lt;br /&gt;&lt;br /&gt;My requirements:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Hands-off/lights-out operation - no human interaction needed to run it.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;At least once a day, back up all changed files in a list of directories to a remote server.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Be able to install it on multiple machines easily.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Don't show a command window while backing up - it might scare my wife.&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:trebuchet ms;"&gt;Run on Windows XP Home.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-family:trebuchet ms;"&gt;My solution combines &lt;a href="http://samba.anu.edu.au/rsync/"&gt;rsync&lt;/a&gt;, &lt;a href="http://www.cygwin.com/"&gt;Cygwin&lt;/a&gt;/&lt;a href="http://www.gnu.org/software/bash/"&gt;bash&lt;/a&gt;, a DOS &lt;a href="http://en.wikipedia.org/wiki/Batch_file"&gt;batch&lt;/a&gt; file, and the Windows &lt;a href="http://support.microsoft.com/kb/308569"&gt;Task Scheduler&lt;/a&gt;.  It runs whenever scheduled, in a minimized command window, and synchronizes an arbitrary list of configured directories to a specified root location on a remote server.&lt;br /&gt;&lt;br /&gt;&lt;span&gt;&lt;span style=";font-family:trebuchet ms;font-size:100%;"  &gt;Install Cygwin from the above link.  Install rsync and &lt;a href="http://www.openssh.com/"&gt;OpenSSH&lt;/a&gt;.  I know, the installer is confusing, but it is free.&lt;br /&gt;&lt;br /&gt;On your server, presumably running some flavor of Unix/Linux with rsync available (many online hosting sites that provide shell accounts make this part of their default setup), do the following:&lt;br /&gt;&lt;blockquote&gt;ssh-keygen -t rsa #type Enter to accept the default file name/location&lt;br /&gt;cd ~/.ssh&lt;br /&gt;cat id_rsa.pub &gt;&gt; authorized_keys&lt;br /&gt;chmod 600 authorized_keys&lt;br /&gt;&lt;/blockquote&gt;This allows any machine with the newly generated key to log into the current shell account on the remote server without a password.  So guard the id_rsa and id_rsa.pub files carefully!&lt;br /&gt;&lt;br /&gt;Copy the id_rsa and id_rsa.pub files to the "source" computer - the one with the files you want to back up.  Put them in ~/.ssh.  You can do this with scp, the ssh-based secure remote copy command in Bash/Cygwin:&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;mkdir ~/.ssh&lt;br /&gt;scp &lt;span style="font-family:trebuchet ms;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style=";font-family:trebuchet ms;font-size:100%;"  &gt;&lt;span style="color: rgb(0, 153, 0);"&gt;[user]&lt;/span&gt;@&lt;span style="color: rgb(0, 153, 0);"&gt;[host.domain]&lt;/span&gt;:~/.ssh/id_rsa* ~/.ssh&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;Now you should be able to log in from the local computer to the remote server without entering the password:&lt;br /&gt;&lt;blockquote&gt;ssh &lt;span style="font-family:trebuchet ms;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style=";font-family:trebuchet ms;font-size:100%;"  &gt;&lt;span style="color: rgb(0, 153, 0);"&gt;[user]&lt;/span&gt;@&lt;span style="color: rgb(0, 153, 0);"&gt;[host.domain]&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/blockquote&gt;Create a directory in the primary user's home directory (NOT My Documents, one level above, in c:\Documents and Settings\[username]).&lt;br /&gt;&lt;br /&gt;In this directory, create a file backup.sh with the following contents:&lt;br /&gt;&lt;blockquote&gt;#!/bin/bash&lt;br /&gt;# DOS command: c:\cygwin\bin\bash.exe -c "~/backup/backup.sh"&lt;br /&gt;export PATH=$PATH:/usr/bin/&lt;br /&gt;rsync -arzve ssh --delete --no-p --no-g --chmod=u+rw,g+r,o-rwx,Dug+rwx --modify-window=1 --files-from ~/backup/files.txt ~/ &lt;span style="color: rgb(0, 153, 0);"&gt;[user]&lt;/span&gt;@&lt;span style="color: rgb(0, 153, 0);"&gt;[host.domain]&lt;/span&gt;:~/&lt;span style="color: rgb(0, 153, 0);"&gt;[server_backup_root_path]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;then make it executable:&lt;br /&gt;chmod a+x backup.sh&lt;br /&gt;&lt;/blockquote&gt;This is the heart of the backup.  See the rsync &lt;a href="http://samba.anu.edu.au/ftp/rsync/rsync.html"&gt;man page&lt;/a&gt; for option descriptions.  Hopefully the parts in green are self-explanatory - these are the pieces specific to your backup server.&lt;br /&gt;&lt;br /&gt;I needed the chmod parameter for my hosting service - may not be needed for all servers.  The --modify-window=1 parameter came from somewhere on the web, I can't find it now, and was important to seeing the right list of changed files.&lt;br /&gt;&lt;br /&gt;The ~/backup/files.txt referenced above is just a plain text file with one relative path per line - relative to the path following the --files-from parameter, in this case the user home directory.  The simplest case might be a files.txt simply containing:&lt;br /&gt;&lt;blockquote&gt;&lt;/blockquote&gt;&lt;blockquote&gt;My Documents/&lt;/blockquote&gt;&lt;blockquote&gt;&lt;/blockquote&gt;If you want to back up your backup script, add "/backup" to the list.  If you don't want all of your "My Documents" folder, you can prune the selections by specifying just specific subfolders:&lt;br /&gt;&lt;blockquote&gt;My Documents/My Music/&lt;br /&gt;My Documents/My Pictures/&lt;br /&gt;My Documents/personal/&lt;br /&gt;&lt;/blockquote&gt;In all cases, the trailing slash is important - I didn't bother figuring out why, it just is, and that was all I needed to know.&lt;br /&gt;&lt;br /&gt;Now the scheduling part.  First, we need a DOS batch file we can run minimized.  Create "backup.bat" with these contents:&lt;br /&gt;&lt;blockquote&gt;title Backing up files...&lt;br /&gt;C:\cygwin\bin\bash.exe -c "~/backup/backup.sh &gt; ~/backup/backup.log 2&gt;&amp;amp;1"&lt;/blockquote&gt;This is just a cryptic command line to start the bash script from a DOS command prompt, sending all output to backup.log.&lt;br /&gt;&lt;br /&gt;Now create a shortcut in the backup directory to the backup.bat file.  I called mine "backupShortcut".  In it's properties, set it to run minimized.&lt;br /&gt;&lt;br /&gt;Go to Control Panels &gt; Scheduled Tasks.  Right click the white space in the window, and select New &gt; Scheduled Task.  Rename it to "daily backup" or something.&lt;br /&gt;&lt;br /&gt;In the properties for the new task, use the following on the "Task" tab:&lt;br /&gt;&lt;blockquote style="font-weight: bold;"&gt;Run: &lt;span style="font-weight: normal;"&gt;"c:\Documents and Settings\[user]\backup\backupShortcut.lnk"&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Start in:&lt;/span&gt; &lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="font-size:130%;"&gt;&lt;span style=";font-family:trebuchet ms;font-size:100%;"  &gt;&lt;span style="font-weight: normal;"&gt;"c:\Documents and Settings\[user]"&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/blockquote&gt;"Run as:" should be set to the current user.  Click "Set Password..." to enter the user's login password.  This lets the job run even if the user is not logged in or the computer is locked.  Yes, this means you can't do this on a computer running Windows XP Home with no password on the primary account.  But everyone should have a password, right?&lt;br /&gt;&lt;br /&gt;Set the schedule to whatever you want.  On my home computers, I do it at 2AM.  On my work laptop, I do it at 2pm, because it is often suspended at night.&lt;br /&gt;&lt;br /&gt;On the "Settings" tab, you may want to change the default length of time before the task is stopped, as the first backup may take a day or two, depending on your upload bandwidth.  Comcast cable, with it's pokey 768K upload limit, can be really a dog the first time you back up pictures and music.&lt;br /&gt;&lt;br /&gt;That should do it!  Run the task manually to make sure a minimized window comes up and stays up.  If there are problems, check the backup.log file for error messages.&lt;br /&gt;&lt;br /&gt;I left out lots of DOS/bash basics, as this was a quick and dirty post to capture my work.  I'll elaborate if anyone needs help.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://www.cygwin.com/"&gt;&lt;/a&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6946864571745885149-5761434015675975732?l=codenoter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codenoter.blogspot.com/feeds/5761434015675975732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6946864571745885149&amp;postID=5761434015675975732' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default/5761434015675975732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default/5761434015675975732'/><link rel='alternate' type='text/html' href='http://codenoter.blogspot.com/2008/10/daily-remote-backups-with-rsync.html' title='Daily Remote Backups with Rsync'/><author><name>Woozy</name><uri>http://www.blogger.com/profile/11819073339164962416</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6946864571745885149.post-1362504024010452868</id><published>2008-10-04T09:03:00.000-07:00</published><updated>2008-10-04T13:05:23.462-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Ehcache'/><category scheme='http://www.blogger.com/atom/ns#' term='clustering'/><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Ehcache RMI Address Determination is Error Prone</title><content type='html'>&lt;span style="text-decoration: underline;font-family:trebuchet ms;" &gt;&lt;/span&gt;&lt;span style="text-decoration: underline;"&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;I had to fix this problem with &lt;a href="http://ehcache.sourceforge.net/"&gt;Ehcache&lt;/a&gt; at work.  We use it with Hibernate in a clustered environment (more on that in another post).  Recently we noticed that sometimes not all peers would discover each other.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;The problem exists in all versions from 1.2.4 on, and is still unchanged in the current 1.5 release &lt;/span&gt;&lt;a style="font-family: trebuchet ms;" href="http://ehcache.svn.sourceforge.net/viewvc/ehcache/branches/ehcache-1.5.0/core/src/main/java/net/sf/ehcache/distribution/RMICacheManagerPeerListener.java?revision=706&amp;amp;view=markup"&gt;here&lt;/a&gt;&lt;span style="font-family:trebuchet ms;"&gt;, on line 166.  Can you spot the problem?&lt;/span&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;span class="hl kwa"&gt;return&lt;/span&gt; &lt;span class="hl kwc"&gt;InetAddress&lt;/span&gt;&lt;span class="hl sym"&gt;.&lt;/span&gt;&lt;span class="hl kwd"&gt;getLocalHost&lt;/span&gt;&lt;span class="hl sym"&gt;().&lt;/span&gt;&lt;span class="hl kwd"&gt;getHostAddress&lt;/span&gt;&lt;span class="hl sym"&gt;()&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;span style="font-family:trebuchet ms;"&gt;Turns out Java doesn't specify exactly what this means on a machine with multiple network interfaces, and the result can vary between machines with similar hardware and operating system (as we found).&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;one of our cluster nodes had a setup that returned an IPv6 interface first, the loopback interface second, and an external IPv4 interface third.  Java returned the loopback address from the above method.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:trebuchet ms;"&gt;Discussion of this Java issue can be found in many threads on the web.  The solution wasn't available until java 1.4, but since almost no one has to use anything less any more, it should be available to most applications.  You need to implement your own subclass of &lt;a href="http://ehcache.sourceforge.net/javadoc/net/sf/ehcache/distribution/RMICacheManagerPeerListenerFactory.html"&gt;&lt;span style="font-family:courier new;"&gt;net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory&lt;/span&gt;&lt;/a&gt; overriding &lt;a href="http://ehcache.sourceforge.net/javadoc/net/sf/ehcache/distribution/RMICacheManagerPeerListenerFactory.html#doCreateCachePeerListener%28java.lang.String,%20java.lang.Integer,%20java.lang.Integer,%20net.sf.ehcache.CacheManager,%20java.lang.Integer%29"&gt;&lt;span style="font-family:courier new;"&gt;doCreateCachePeerListener&lt;/span&gt;&lt;/a&gt; to return a new instance of a subclass of &lt;a href="http://ehcache.sourceforge.net/javadoc/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html"&gt;&lt;span style="font-family:courier new;"&gt;net.sf.ehcache.distribution.RMICacheManagerPeerListener&lt;/span&gt;&lt;/a&gt; which overrides &lt;a href="http://ehcache.sourceforge.net/javadoc/net/sf/ehcache/distribution/RMICacheManagerPeerListener.html#calculateHostAddress%28%29"&gt;&lt;span style="font-family:courier new;"&gt;calculateHostAddress&lt;/span&gt;&lt;/a&gt; &lt;span style="font-family:trebuchet ms;"&gt;to discover the local host address in a more flexible manner.&lt;/span&gt;&lt;/span&gt; &lt;span style="font-family:trebuchet ms;"&gt; Register the factory class in your &lt;span style="font-family:courier new;"&gt;ehcache.xml&lt;/span&gt; configuration file.&lt;br /&gt;&lt;br /&gt;The new code can look something like this:&lt;br /&gt;&lt;blockquote style="font-family: courier new;"&gt;Enumeration&lt;networkinterface&gt; interfaces;&lt;br /&gt;try {&lt;br /&gt; &lt;/networkinterface&gt; &lt;networkinterface&gt;interfaces = NetworkInterface.getNetworkInterfaces();&lt;br /&gt;} catch (SocketException e) {&lt;br /&gt;    &lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;networkinterface&gt;throw new UnknownHostException("Error getting network interfaces: ".concat(e.getLocalizedMessage()));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if (interfaces == null) {&lt;br /&gt;    &lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;networkinterface&gt;throw new UnknownHostException("No network interfaces found");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;InetAddress addrToUse = null;&lt;br /&gt;&lt;br /&gt;while(interfaces.hasMoreElements()) {&lt;br /&gt;&lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;NetworkInterface i = interfaces.nextElement();&lt;br /&gt;   &lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;Enumeration&lt;inetaddress&gt; addresses = i.getInetAddresses();&lt;br /&gt;if (addresses == null) continue;&lt;br /&gt;&lt;br /&gt;&lt;/inetaddress&gt;&lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;&lt;inetaddress&gt;while(addresses.hasMoreElements()) {&lt;br /&gt;         &lt;/inetaddress&gt;&lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;&lt;inetaddress&gt;InetAddress a = addresses.nextElement();&lt;br /&gt;         &lt;/inetaddress&gt;&lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;&lt;inetaddress&gt;if (addrToUse == null &amp;amp;&amp;amp; ! a instanceof Inet6Address) addrToUse = a;&lt;br /&gt;   &lt;/inetaddress&gt;&lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;&lt;inetaddress&gt;}&lt;br /&gt;}&lt;br /&gt;if (addrToUse == null) {&lt;br /&gt;&lt;/inetaddress&gt;&lt;/networkinterface&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;networkinterface&gt; &lt;/networkinterface&gt; &lt;/span&gt;&lt;/span&gt;&lt;networkinterface&gt;&lt;inetaddress&gt;throw new UnknownHostException("No IPv4 non-loopback address found for any interface.");&lt;br /&gt;}&lt;br /&gt;return addrToUse.getHostAddress();&lt;/inetaddress&gt;&lt;/networkinterface&gt;&lt;/blockquote&gt;This returns the String representation of the first IPv4, non-loopback address found.  The assumption here is that Java will always return the interfaces and addresses in the same order, given the machine network settings haven't changed.&lt;br /&gt;&lt;br /&gt;If you want to fall back on the loopback address, if found, modify the above code accordingly.  I'll leave that as an exercise for the reader (oops, my math background is showing).&lt;br /&gt;&lt;br /&gt;With this updated host lookup code our app didn't need different configuration files for each instance, and all nodes automatically discovered each other, even between machines with multiple network interfaces, such as modern rack servers with multiple NICs and automatic failover between them.&lt;br /&gt;&lt;br /&gt;Eventually I'll post about all the pieces we use to run a single Java web application in multiple Tomcat instances on multiple servers with Hibernate and an L2 Ehcache on each one, without the overhead of Tomcat clustering or a full-blown application server.  All nodes sharing the same database automatically discover eachother and keep their cache contents in sync without any special configuration on individual nodes.  Pretty cool.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6946864571745885149-1362504024010452868?l=codenoter.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codenoter.blogspot.com/feeds/1362504024010452868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6946864571745885149&amp;postID=1362504024010452868' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default/1362504024010452868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6946864571745885149/posts/default/1362504024010452868'/><link rel='alternate' type='text/html' href='http://codenoter.blogspot.com/2008/10/ehcache-rmi-address-determination-is.html' title='Ehcache RMI Address Determination is Error Prone'/><author><name>Woozy</name><uri>http://www.blogger.com/profile/11819073339164962416</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
