How to backup and sync your rooted Android phone automatically

1 03 2012

I have for a while now been working on a custom automatic sync solution for my HTC Hero running Froyo (Froydvillain ROM). As I am a Linux junkie and love scripts and hacks I wanted to do it all via cunning hacks and I’ve finally got it nailed.

This solution uses Scripting Layer 4 Android (SL4A) and Tasker alongside a custom ROM with rsync (any ROM should do so long as it has rsync). For those that don’t know, rsync is an awesome application that allows for remote backup and sync across machines. It turns out you don’t even need a ROM with rsync built in, as you can install an app that provides rsync, the app is called rsync backup for android and can be found here: https://market.android.com/details?id=eu.kowalczuk.rsync4android&hl=en

The only issue is you can’t call rsync from the command line using simply “rsync” since it isn’t in your systems path. However, if you use the following string instead,replacing calls to “rsync” with the following, the scripts still work: /data/data/eu.kowalczuk.rsync4android/files/rsync

SL4A is used to set out what to do via a script. You can write scripts in various languages in SL4A but I am using Bash as I am familiar with it. Rsync is used to actually handle the sync / backup and Tasker is used to launch the scripts when certain conditions are met.

I have created two scripts in SL4A, one backups my photos folder to my main photo folder on my server. The server runs the rsync daemon which rsync on the phone connects to. The other script does the reverse and copies a remote folder in my server that contains a bunch of music to my phone.

Tasker is set up with a profile that activates when my phone is plugged in and it’s between midnight and 7.00 am. This then connects to my WiFi network and then runs the two scripts via the SL4A plugin. Since I charge my phone each night this is effectively automatic.

The key here is getting permissions correct with rsync during the file transfer, as the memory card uses fat32 it hasn’t got any permissions. The rsync daemon doesn’t like this and errors out, hence the need for various settings. The second key here is exporting your password as an environmental variable. This is inherently insecure but since my server has multiple redundant backups and is only locally accessible I don’t care much. I could use trusted keys but I’m too lazy.

Here are the two scripts. First the music script that syncs from server to phone:

#rsync sync
export RSYNC_PASSWORD=password
DATE=$(date)
LOG=/mnt/sdcard/rsyncmusic.txt
echo rsync started $DATE > $LOG
TRY=1
rsync_com ()
{
DATE=$(date)
if [ $TRY = 15 ]; then
echo rsync failed, quitting on $DATE >> $LOG
exit
fi
sleep 10
echo rsync attempt $TRY started $DATE >> $LOG
rsync --progress -vHrltD --chmod=Du+rwx,go-rwx,Fu+rw,go-rw --no-perms --stats --password-file=/mnt/sdcard/scrt prupert@prupert::amusic /mnt/sdcard/amusic >> $LOG 2>&1
EXIT=$?
TRY=`expr $TRY + 1`
echo exit code is $EXIT >> $LOG
echo "********************" >> $LOG
}
rsync_com
while [ $EXIT != 0 ]; do
rsync_com
done
echo rsync finished $DATE >> $LOG
exit

The second script syncs the phones photos folder to my server:

#rsync sync photo
export RSYNC_PASSWORD=password
DATE=$(date)
LOG=/mnt/sdcard/rsyncphoto.txt
echo rsyncphoto started $DATE > $LOG
TRY=1
rsync_com ()
{
DATE=$(date)
if [ $TRY = 15 ]; then
echo rsync failed, quitting on $DATE >> $LOG
exit
fi
sleep 10
echo rsync attempt $TRY started $DATE >> $LOG
rsync -vHrltD --chmod=Du+rwx,go-rwx,Fu+rw,go-rw --no-perms --stats --password-file /mnt/sdcard/scrt /mnt/sdcard/DCIM prupert@prupert::apics >> $LOG 2>&1
EXIT=$?
TRY=`expr $TRY + 1`
echo exit code is $EXIT >> $LOG
echo "********************" >> $LOG
}
rsync_com
while [ $EXIT != 0 ]; do
rsync_com
done
echo rsync finished $DATE >> $LOG
exit

I have put some logging in to check progress and also some retry code that retries the sync if it timesout. It seems my HTC Hero’s WiFi connection claps out after a while so the script retries up to 15 times to run successfully based on the rsync exit code.





Use Dropbox as Your Own Personal Source Repository

10 08 2010

Dropbox is an awesome little service, allowing you to sync various files between devices (PCs, Andriod and iPhones for example). Whilst there are lots of uses of the Dropbox service, I tend to use it for two main things.

The first is as my own personal SVN-esque server. I set up a folder in my main Dropbox “root” directory, by default in Windows this is under “My Documents/My Dropbox”. Any code I write, I save in this folder. The code is then synced to all my PCs automatically by Dropbox, allowing me to work on the code from anywhere. As I use Eclipse to write my code, I have set this folder as the default source folder for my workspace in both my Windows and Ubuntu version of Eclipse. Thus, all I need to is open up Eclipse and hit F5 to refresh and get all my updated sources, thanks to Dropbox!

I do the same for the music tracks I am working on under Renoise. By saving all my songs in a folder under the main Dropbox folder, the tracks are synced across all my accounts. As Renoise is cross-platform (to a degree) I can simply open up Renoise on both my Windows and Ubuntu machines and work on the same track. Sweet. This trick works for any cross platform program. You can do it for your Firefox or Google Chrome profiles, or even your Music Library!





The Best, Most Useful and Most Awesome Android Apps

9 08 2010

I’m a big fan of Google’s Android OS and have been using my Android phone for about ten months now. It seems one of the most common questions on the interwebosphere related to Android is “What are the best Android apps?”. Well, I aim to give my small contribution to that question by listing the apps I use most often on my HTC Hero running Android 2.1.

First off, there is the choice over the biggest app of all, which version of Android to use. Although I use a HTC Hero, I am not a big fan of the Sense interface, so instead I have chosen to install a vanilla (plain) rooted version of Android. As I am using a custom ROM (the name given to the OS that the phone runs) I can choose to use a more modern version of Android than is currently available on the HTC Hero. Thus, whilst other UK Orange HTC Hero users are still waiting for Orange to get their update out there, I have been rocking Android 2.1 for over two months now. I use RaduG’s VanillaEclair ROM which is pretty damn perfect. For those that don’t know, the advantage of running a rooted version of a ROM means you can install certain apps that have added functionality and you have greater control over your phone, more about this later.

The second most important app (and from now on I am only talking about real apps here) is what Home app to use. The Home app is the one that you see and use almost all the time. It is the first screen you see after you unlock your phone and it is what displays the menu of all your apps . The default Android Home app isn’t bad, but there is certainly room for improvement. There are a number of Home apps out there, both free and paid for with various functions. I have settled on the rather awesome LauncherPro. LauncherPro is based on the stock Android Home app, but it has a myriad of improvements. First off, it has a dock at the bottom, that is fully customisable, allowing you to put shortcuts to apps, contacts and folders right on the bottom of your Home screen. Even better, you can have up to three docks, which you can swype between, so you can have 12 shortcuts. Furthermore, a newly released feature allows you to add a gesture shortcut to each of those shortcuts, so swiping up on a shortcut opens up another shortcut, so you can have in effect 24 shortcuts in all. As you can see on my screenshot, I have a shortcut for the browser, the phone, messaging and gmail. The middle “blocks” button takes me to my menu of apps. You can also see another excellent feature of LauncherPro, the ability to give message indications for certain shortcuts, in this screenshot it is showing I have 2 unread gmails, ooh, how popular I am. LauncherPro also features some of the more popular features from alternative Home apps, like ADW Launcher and HTC’s Sense – a “helicopter” overview of all your home screens and scrollable widgets, more about them in second. There are two versions of LauncherPro, the free version, called LauncherPro and a paid for improved version called LauncherPro Plus. LauncherPro Plus includes additional features (and more are being added all the time), the main ones are three built-in widgets: bookmarks, calendar and people. You can see the calendar widget in the screenshot to the right, it basically shows you your upcoming appointments. The great thing is that it is scrollable, so you can scroll through about a month ahead to see what is coming up. The people widget shows a pre-selected group from your contacts and is also scrollable, clicking on a contact pops up a context sensitive menu with various options to interact with that person. The bookmark widget shows thumbnails of all your bookmarks, though I have not used that widget yet, so can’t say more than that. I’d highly recommend the Plus version, if only to support the excellent developer of LauncherPro, as it is a one-man show.

My next awesome app is Tasker, but I have already mentioned this app in a previous post so I wont go on about it here. Basically, Tasker allows you to set up various profiles that enable or disable various settings. It essentially allows you take full control of your phone. Lifehacker wrote some cool guides on how to take full advantage of Tasker. You can see some examples of the profiles I use in the screenshot to the right. So, for example during the day, I turn on my data connection and auto-sync, but at night these are off, to save battery power. Another profile simply notifies me when the phone is charged, so I don’t leave it plugged in the charger for an age. It is an incredibly powerful tool and helps you take total control over your phone.

Up next is Titanium Backup. This app only works on a phone with a rooted ROM, as I mentioned earlier. It’s one of those awesome apps that you keep installed and only use occasionally, but is very useful when you use it. It allows you to backup all your apps and their associated data. Then, when you come to install a new ROM, you can simply restore that backup and all your apps, with all their settings as you left them. Nice. You can also use it to backup pretty much anything else as well, such as your contacts, text messages, browser bookmarks etc etc.

Next on the list is the rather awesome CoPilot Live v8. Whilst Google’s Navigation app is certainly useful, it only works online and gets into trouble if you veer off course without an internet connection – which in the UK can happen from time to time, especially if you are on Orange. CoPilot is in a whole different league when it comes to SatNav apps. It is just beautiful, works really well and is very easy to use. It has a few additional features, like nearby Points Of Interest indicators, the ability to route missing out toll roads and bridges and live tracking. You can buy maps for most of the major countries in Europe and the United States for a reasonable amount (way cheaper than the cost of maps for v7). I used it on an 8 hour round-trip and it didn’t flake out on me once. Because all the maps are stored on your SD card, it works offline, so you never loose where you are or where you are going. I wouldn’t be surprised if they come out with a new version next year supporting 3D models of buildings in major cities, ala Google Earth, but that will no doubt require the purchase of a new licence and no doubt a new phone to power it all!

Next on the list is the rather cool SystemPanel. This is a great app for keeping an eye on your phone to make sure it is running OK. It shows you which apps are running, how much memory is being used and which apps are thrashing your CPU (and hence killing your battery). It also allows you to monitor CPU and battery usage as well as data usage. Furthermore, it has an app archive facility allowing you to backup non-protected apps. It does have the ability to kill tasks and apps to “free memory”, but this is advised against, as Android is designed to use up as much memory as possible, just like Linux, so you are always going to be “low on memory”. Android kills apps itself if another app needs more memory, so task killers really aren’t useful. I use it if an app is misbehaving and to track down what app is maxing out my CPU and generally to keep tabs on my phone. It has a lovely GUI and is very reliable.

My final app that I would recommend is the BBC News widget by Jim Blackler. It might only be useful to users in the UK, although it does show World news if you want. It is by far the best news widget I have found. I did use AnyRSS Reader for a long time, but I never liked not having an image to view and it took up too much screen space. The BBC News widget takes up only one “slot” on your home screen, yet manages to squeeze a picture and an informative headline into that space. You can set it to regularly update throughout the day, so whenever you turn your phone on, you are always aware of the latest news around the world. You can see it in action in the screen shot a few images above, showing the news headlines (quite why the BBC thinks an article on being single is a news headline is any one’s guess, but that’s modern media for you) and David Cameron’s latest foreign policy gaff.

There is one more app that I use everyday, but it is quite specific to me. IP Cam Viewer is a great app if you need easy and quick access to images from an IP Webcam. I have a baby daughter and have set up a night-vision webcam to monitor her during the night and day when she sleeps. IP Cam Viewer allows me to keep tabs on her late at night and when it gets dark when we are putting her to bed. The developer of the app is very active, updating it constantly and it even supports audio from some webcams.

It worked perfectly with my cheap Fosscam ripoff from eBay (until I punched a hole through the microphone by accident and the plug literally fell apart in my hand!). If you need a way to view webcam images on your phone, I would highly recommend it.

That then is about it for my favourite apps on Android. Here are some other apps that I use occasionally that deserve an honorable mention: Astrid (for managing your daily tasks), Andromote (an awesome UPnP client), APNdroid (for turning off your data connection), Barcode Scanner (you know, for scanning barcodes), ConnectBot (for logging in to PCs via SSH), Dropbox (for sharing files), DroidWiki (for making awesome TiddlyWiki style notes), ES File Explorer (for browsing my files on the phone and on the LAN), Power Strip and Quick Settings (for quick access to various settings no matter what app you have open) and WaveSecure (for tracking my phone if it is lost or stolen and for backing up contacts online).

I hope you like the apps listed here. It is interesting to note that all the apps I have mentioned are paid-for. Whilst the majority of the apps mentioned here come in a “free” version, I find I like to thank the dev for all their hard work so am happy to upgrade to the fully featured versions.








Follow

Get every new post delivered to your Inbox.