Android and Linux

Wednesday, July 21, 2010

Backup photos with rsync

I've never used rsync much but have always wanted to try it more. Maybe it was my inexperience or maybe it's the non-standard Android version, but it turned out to be a pain!

I started with a generic rsync command and customized it, but every step failed and I had to find the answer why. Then, after a successful connection and transfer, it threw errors on every file, which I found was due to a bug in some versions of rsync, so I had to find a workaround to that.

At any rate, here is a basic, working rsync command for transferring photos from the phone to a computer.

It can be used to back up any directory by changing "/sdcard/DCIM/Camera" to the directory you want to backup. It can also transfer files from the computer to the phone by changing the order of the two paths from /sdcard/DCIM/Camera COMPUSER@IP:/PATH/TO/SYNC/TO to COMPUSER@IP:/PATH/ON/COMP /PATH/ON/PHONE
#! /system/bin/sh
rsync -rltDv -e "ssh -l USER -i /PATH/TO/SSHKEY" /sdcard/DCIM/Camera USER@IP:/DIR/TO/SYNC/TO
Copy "syncpics" to your clipboard with this QR code, but don't forget to edit it to fill out your login information.