Articles :: System Administration :: iPod + Ant = Portable Backup System

written by Toby Miller on February 1, 2007
February 1, 2007

I was copying some files to my iPod one day to work on at home (the vpn was down for maintenance). Then it hit me, why do I do this by hand? I have Ant! So off I went, tap tapping away, and a few minutes later I had an Ant script that would grab my most valued file folders from my computer and synchronize them with a duplicate copy on my iPod. Now whenever I need to take some work home with me I just plug in my iPod, execute my Ant task, wait a few minutes, and my iPod has a complete up-to-date copy of my most valued file folders. Simple, eh?

I'm sure there are lots of things I could do to make these tasks more efficient, but I quit when it started doing what I needed it to. So if you see room for improvements please let me know.

build.xml - remember to update the paths to apply to your system
   1:<project name="pc-backup" default="info">
   2:    <property name="ipod.path" value="G:"/>
   3:    <property name="separator" value=""/>
   4:    <property name="verbose" value="true"/>
   5:
   6:    <target name="info">
   7:        <!-- usage statement -->
   8:        <echo message="sync2ipod: sync folders from your pc to your ipod"/>
   9:    </target>
  10:
  11:    <target name="init" description="prepare for a sync">
  12:        <!-- this is a personal backup, leave the version control files intact -->
  13:        <defaultexcludes remove="**/CVS"/>
  14:        <defaultexcludes remove="**/CVS/**"/>
  15:        <defaultexcludes remove="**/.cvsignore"/>
  16:        <defaultexcludes remove="**/SCCS"/>
  17:        <defaultexcludes remove="**/SCCS/**"/>
  18:        <defaultexcludes remove="**/vssver.scc"/>
  19:        <defaultexcludes remove="**/.svn"/>
  20:        <defaultexcludes remove="**/.svn/**"/>
  21:        <tstamp>
  22:            <format property="stamp.record" pattern="yyyyMMdd_HHmmss"/>
  23:        </tstamp>
  24:
  25:        <!-- record the current priority level -->
  26:        <nice currentpriority="old.priority"/>
  27:
  28:        <!-- start a log -->
  29:        <record name="${ipod.path}${separator}${ant.project.name}${separator}ant_${stamp.record}.log" action="start"/>
  30:    </target>
  31:
  32:    <target name="cleanup" description="cleanup after ourselves">
  33:        <!-- stop the log -->
  34:        <record name="${ipod.path}${separator}${ant.project.name}${separator}ant_${stamp.record}.log" action="stop"/>
  35:
  36:        <!-- reset the priority level -->
  37:        <nice newpriority="${old.priority}"/>
  38:    </target>
  39:
  40:    <target name="syncfile" description="sync file from one path to another">
  41:        <!-- srcpath = real file, destpath = copied file -->
  42:        <echo message="syncing from ${srcpath} to ${destpath}"/>
  43:        <copy file="${srcpath}" tofile="${destpath}" overwrite="false" verbose="${verbose}" granularity="2000"/>
  44:        <sleep seconds="1"/>
  45:    </target>
  46:
  47:    <target name="syncdir" description="sync from one directory to another">
  48:        <!-- srcdir = real dir, destdir = copied dir -->
  49:        <echo message="syncing from ${srcdir} to ${destdir}"/>
  50:        <sync todir="${destdir}" overwrite="false" includeEmptyDirs="true" verbose="${verbose}" granularity="2000">
  51:            <fileset dir="${srcdir}"/>
  52:        </sync>
  53:        <sleep seconds="1"/>
  54:    </target>
  55:
  56:    <target name="sync2ipod" depends="init" description="sync chosen files to my ipod">
  57:        <!-- sync the build.xml file itself -->
  58:        <antcall target="syncfile">
  59:            <param name="srcpath" value="E:${separator}build.xml"/>
  60:            <param name="destpath" value="${ipod.path}${separator}${ant.project.name}${separator}build.xml"/>
  61:        </antcall>
  62:
  63:        <!-- sync my valued folders (edit this section to suit your own needs) -->
  64:        <antcall target="syncdir">
  65:            <param name="srcdir" value="E:${separator}shared"/>
  66:            <param name="destdir" value="${ipod.path}${separator}${ant.project.name}${separator}shared"/>
  67:        </antcall>
  68:        <antcall target="syncdir">
  69:            <param name="srcdir" value="E:${separator}projects"/>
  70:            <param name="destdir" value="${ipod.path}${separator}${ant.project.name}${separator}projects"/>
  71:        </antcall>
  72:
  73:        <!-- cleanup after yourself -->
  74:        <antcall target="cleanup"/>
  75:    </target>
  76:
  77:    <target name="sync2ipodlow" depends="init" description="sync chosen files to my ipod with minimum cpu priority">
  78:        <!-- set priority as low as possible -->
  79:        <nice newpriority="1"/>
  80:        <nice currentpriority="new.priority"/>
  81:        <echo message="changed priority from ${old.priority} to ${new.priority}"/>
  82:
  83:        <!-- continue with sync -->
  84:        <antcall target="sync2ipod"/>
  85:    </target>
  86:
  87:    <target name="sync2ipodhigh" depends="init" description="sync chosen files to my ipod with maximum cpu priority">
  88:        <!-- set priority as high as possible -->
  89:        <nice newpriority="10"/>
  90:        <nice currentpriority="new.priority"/>
  91:        <echo message="changed priority from ${old.priority} to ${new.priority}"/>
  92:
  93:        <!-- continue with sync -->
  94:        <antcall target="sync2ipod"/>
  95:    </target>
  96:</project>
  97:

So plug in your ipod, edit this ant file to match the paths on your machine and execute it with ant sync2ipod. Now just remember to use it once a day, or as often as you'd like, and voila! Your iPod just went from being a cool mp3 player to being a cool mp3 player and portable synchronized backup utility device. =)

permalink                                                                                                                                                                          
   Natural Living (5)
      Heating & Cooling (1)
      Herbal Remedies (1)
   Personal (0)
      Family (1)
      Humor (11)
      Miscellaneous (1)
      Politics (5)
   Technology (2)
      System Administration (4)
            Linux (1)
            Solaris (0)
      Web Development (2)
            CSS (3)
            Design (1)
            Flash (1)
            JavaScript (11)
            PHP (1)
                        CakePHP (1)
            Web Browsers (2)
                        Firefox (1)
                        Internet Exploder (0)
                        Netscape (1)
printed @ tobymiller.com
(currently rendering CSS for Internet Explorer)(currently rendering CSS for non-Internet Explorer browsers)