Android, ASE and rsync

I happened to notice that the rsync command was included on my HTC Desire, so I figured I could use it to send scripts to the device, but it also doubles as a very convenient way to backup my pictures and stuff. (It’s probably most convenient for unix users – which is whom this write-up is intended for. You can get rsync for Windows as well, but I haven’t used it much. YMMV.)

Anyway, to get started you need an rsyncd.conf file. Here’s mine, which I chose to place at /sdcard/rsyncd.conf:

port = 1234
pid file = /sdcard/rsyncd.pid

[data]
    path = /
    list = false
    use chroot = false
    read only = false

Then I wrote two tiny shell scripts with ASE to start and stop the service:

start_rsync.sh:

rsync --config=/sdcard/rsyncd.conf --daemon

and stop_rsync.sh:

pid=`cat /sdcard/rsyncd.pid`
kill $pid
rm /sdcard/rsyncd.pid

Yes, I should add some sanity checks to verify it’s stopped or running, but I’m lazy. :P

I put short-cuts to the latter two on my phone’s “desktop” for easy access. Leaving it running permanently might not be such as good idea, unless you add rsync authentication. Or never use untrusted networks.

Anyway, with this setup you can easily copy scripts to the phone like so;

rsync blah.py rsync://192.168.1.100:1234/data/sdcard/ase/scripts/

Or backup your scripts (say, if you edit them on the phone);

rsync -av rsync://192.168.1.100:1234/data/sdcard/ase/ $HOME/ase-backup/

Or just browse:

rsync rsync://192.168.1.100:1234/data/

(And if you don’t realize that you have to replace the IP address above with whatever address your device was assigned, this post probably isn’t for you.)

Hope someone finds this tip useful. I know I find it very handy. :)

This entry was posted in android, tech. Bookmark the permalink.

7 Responses to Android, ASE and rsync

  1. bluppfisk says:

    Will I need to root my device to use this? I’ve mostly received permission denied errors when trying to sync my phone with my online storage that has rsync support.

    Someone should write a frontend for it… is programming for android hard?

    • vidar says:

      No, you don’t need a rooted device. All you need is the Android Scripting Environment and the snippets above.

      The file permissions used on the SD card on the device are a bit peculiar, so you might want to try adding the option --chmod=Dug+rx,ug+r to the rsync command line in the receiving end.

      • tom says:

        Thanks vidar, I had the same permission problem with my rsync backup script and couldn’t found the right parameter,
        –chmod=Dug+rx,ug+r
        made everything works fine.
        I can now backup my SD directly from my milestone to my backup server, just like my laptop :)

  2. VTR1000 Lady says:

    Great detailed information, I just bookmarked you on my google reader

    Sent from my Android phone

  3. Larry says:

    Will “Proxy” work w/DroidX (Verizone SmartPhone)? Is there, or is there contemplated an interface for this device?

    Thanks.

    Larry

  4. Callum says:

    Useful writeup. There’s a front end that does this stuff for you called rsyncdroid. It took me a minute to figure out that it manages an rsync daemon on the phone, I wanted an rsync client! :-)

  5. It’s working in my HTC with Froyo 2.2

    Thanks!!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>