Setup Action Intent to Invoke File Sync

209 views
Skip to first unread message

Hussain

unread,
Jun 14, 2011, 7:58:24 AM6/14/11
to Tasker
Hi, I need to setup auto file sync to backup my Nandroids weekly from
my SDCARD to my PC. For this, I have downloaded an app from Market
called 'FSync'. Now I need to initiate the sync once a week. I need to
do this from Tasker as the app does not have a scheduler. However, the
author has provided the Action Intent for Sync Initiation :

Intent ftpIntent = new Intent(Intent.ACTION_VIEW, ftp://anon...@server.com);
startActivity(Intent.createChooser(ftpIntent, "OpenWith"));

How can I link this with Tasker so that I can initiate the backup
weekly. Please help.

p/s : Link to the Author site :
http://www.unisaran.com/products/fsync.html

Corey Z

unread,
Jun 14, 2011, 11:08:36 AM6/14/11
to tas...@googlegroups.com
Is your PC on your local network and/or do you have SSH access to it? 

If so, I would recommend setting up an rsync server on your pc. In my opinion, it's a much better way to do backups. It has the ability to do deltas so it'll only sync what has changed since your last backup.  If you're interested, there is an rsync app on the market that has Tasker functionality out of the box.

Hussain

unread,
Jun 14, 2011, 6:10:20 PM6/14/11
to Tasker
Dear Corey,
Thanks for the recommendation. I actually had considered about using
that. However, the problem lies with me having a Windows Machine (W7
x64), where RSYNC being Linux based is not very friendly running on
Windows. I searched for hours on Google trying to get a guide on
setting up a Rsync server on windows but to no avail.
I downloaded some software on Windows like Delta Copy but didn't work.
Therefore, I emailed the developer of Rsync for Android.
He replied and I quote "Delta Copy uses native rsync protocol (without
SSH tunnelling), but currently my app support only rsync over SSH.
Changing that is in my TODO list, but currently I don't have time to
develop the app"
Therefore, I went around looking for other solutions.
In this case Corey, I would really love if you could help me with
detailed steps on setting up a Rsync server with SSH on a Windows
Machine.
If that isn't the case, then please suggest me some alternatives.
Thank you. Appreciate your help.

On Jun 14, 11:08 pm, Corey Z <czua...@gmail.com> wrote:
> Is your PC on your local network and/or do you have SSH access to it?
>
> If so, I would recommend setting up an rsync server on your pc. In my
> opinion, it's a much better way to do backups. It has the ability to do
> deltas so it'll only sync what has changed since your last backup.  If
> you're interested, there is an rsync app on the market<http://market.android.com/details?id=eu.kowalczuk.rsync4android>that has Tasker functionality out of the box.

Corey Z

unread,
Jun 15, 2011, 9:35:22 AM6/15/11
to tas...@googlegroups.com
Here's a good guide for getting rsync setup on a windows machine. It uses a program called cygwin which allows Windows users to use linux commands on their Windows OS.

If you want to bypass the need for SSH, you can use SL4A coupled with a python script I wrote to do just this.
This method might have a lot of steps but it has worked for me and is efficient enough to do delta backups of my 32gb sdcard nightly :)

Once you have rsync setup you can follow these steps to get the phone portion working.
  1. Download and install the SL4A app
  2. Download and install the python module (after installation, this needs to be opened and click the install button inside)
  3. Follow the instructions here to download and install the rsync binary (note that the system mounting is specific to each phone and is only usable if you're rooted)
  4. Once you have SL4A setup, create a python script called "rsync.py" and paste my python script into it
  5. Go into the script and make changes to suit your environment (ex: path to rsync and the IP of your server)
  6. Finally, go into Tasker and go to plugins, select SL4A and then select your script to run
If you have any other questions, I'll do my best to help.

Good luck.

-Corey

fubaya

unread,
Jun 15, 2011, 10:56:16 AM6/15/11
to Tasker
Android has rsync built in so you shouldn't need an app. I have ssh
running and just run this command with the locale execute plugin with
tasker.

http://a-more-common-hades.blogspot.com/2010/07/backup-photos-with-rsync.html

Hussain

unread,
Jun 15, 2011, 2:58:53 PM6/15/11
to Tasker
Dear Corey, I managed to complete up to step 2 successfully. In step
3, when I run this code(" mv /sdcard/rsync /system/xbin/rsync") in
Terminal Emulator, I get this error "mv : can't rename 'sdcard/rsync':
No such file or directory'
Please help me with where I am doing wrong. Thank you.

p/s : i copied the rsync file to root of my sdcard and Also mounted
system as R/W.

On Jun 15, 9:35 pm, Corey Z <czua...@gmail.com> wrote:
> Here's a good guide <http://www.gaztronics.net/rsync.php> for getting rsync
> setup on a windows machine. It uses a program called cygwin which allows
> Windows users to use linux commands on their Windows OS.
>
> If you want to bypass the need for SSH, you can use SL4A<http://code.google.com/p/android-scripting/>coupled with a python script I wrote to do just this.
> This method might have a lot of steps but it has worked for me and is
> efficient enough to do delta backups of my 32gb sdcard nightly :)
>
> Once you have rsync setup you can follow these steps to get the phone
> portion working.
>
>    1. Download and install the SL4A app<http://code.google.com/p/android-scripting/downloads/detail?name=sl4a...>
>    2. Download and install the python module<http://code.google.com/p/android-scripting/downloads/detail?name=Pyth...> (after
>    installation, this needs to be opened and click the install button inside)
>    3. Follow the instructions here<http://www.droidforums.net/forum/droid-hacks/9673-howto-setup-rsync.html> to
>    download and install the rsync binary (note that the system mounting is
>    specific to each phone and is only usable if you're rooted)
>    4. Once you have SL4A setup, create a python script called "rsync.py" and
>    paste my python script <http://pastebin.com/HBsF45Sa> into it
>    5. Go into the script and make changes to suit your environment (ex: path
>    to rsync and the IP of your server)
>    6. Finally, go into Tasker and go to plugins, select SL4A and then select

Corey Z

unread,
Jun 16, 2011, 9:26:55 AM6/16/11
to tas...@googlegroups.com
I'm assuming that you're rooted if you can remount your system partition (if you're not, then that's an another issue entirely).

If you are rooted properly and can remount your system partition without error, try the next steps.
  1. Check to see if you have an /xbin folder by first getting super user access ("su" first) in a terminal and then entering "cd /system/xbin"
  2. If you get an error about no such file/folder, mount r/w and enter "mkdir /system/xbin"
  3. Try a different method of copying by entering "cat /sdcard/rsync > /system/xbin/rsync"
  4. If that works, you can keep following the original instructions I posted. If not, then you're probably not rooted correctly or the commands you're using to remount the system partition are not working.
Additionally, the post by fubaya did raise a good point. You can use the Locale Execute plug-in on the market. However, the logging capabilities are not that great and you would be unable to determine if the rsync command even ran/succeeded/failed without digging into the logcat. I had originally tried this plug-in to accomplish what I set out to and ended up using SL4A instead. My script will create a notification when the rsync command finishes/errors out so you can at least see the outcome of the process.

Hope this helps.

-Corey

Hussain

unread,
Jun 16, 2011, 1:52:20 PM6/16/11
to Tasker
Dear Corey, I was unable to copy the rsync file using terminal/adb.
So, instead, I just used Root Explorer to copy the 'rsync' file to /
system/xbin/rsync

Next, I edited your py script to suit my server add. Here is the
outcome :

import android
import os

droid = android.Android()
droid.wakeLockAcquireDim()
retcode = os.system("rsync -av /sdcard/Apk 192.168.0.5::backup/ --size-
only --stats --progress --delete-excluded")
if retcode != 0:
droid.notify('Rsync Process Failed', 'Return code: ' +
str(retcode))
else:
droid.notify('Rsync Process Succeeded', 'Sync process complete.
Return code: ' + str(retcode))
droid.wakeLockRelease()

I saved the above script in sl4a as python script and run it. I get
error 'rsync : permission denied (return code 32256)

I think that my remote path is incorrect. So, by running 'ls' on my
cygwin folder on my PC, the list of folders are :
bin
dev
etc
home
lib
tmp
usr
var

So, for me to point to a remote folder, where do I place it into.
Currently i'm using 'home' folder. But im not sure if it is correct.
Please care to explain. Thank you.

On Jun 16, 9:26 pm, Corey Z <czua...@gmail.com> wrote:
> I'm assuming that you're rooted if you can remount your system partition (if
> you're not, then that's an another issue entirely).
>
> If you are rooted properly and can remount your system partition without
> error, try the next steps.
>
>    1. Check to see if you have an /xbin folder by first getting super user
>    access ("su" first) in a terminal and then entering "cd /system/xbin"
>    2. If you get an error about no such file/folder, mount r/w and enter
>    "mkdir /system/xbin"
>    3. Try a different method of copying by entering "cat /sdcard/rsync >
>    /system/xbin/rsync"
>    4. If that works, you can keep following the original instructions I

fubaya

unread,
Jun 16, 2011, 6:20:12 PM6/16/11
to Tasker


On Jun 16, 9:26 am, Corey Z <czua...@gmail.com> wrote:

> Additionally, the post by fubaya did raise a good point. You can use the
> Locale Execute plug-in on the market. However, the logging capabilities are
> not that great and you would be unable to determine if the rsync command
> even ran/succeeded/failed without digging into the logcat.

That's a good point. Rsync actually gives you a lot of output, it just
depends on what you want. For syncing photos, I do:

[rsync command] | grep -c "_" > /sdcard/sync.log
then flash the contents of /sdcard/sync.log with Tasker. That tells me
how many were synced

Corey Z

unread,
Jun 16, 2011, 6:36:52 PM6/16/11
to tas...@googlegroups.com
Before you execute the script, first try to see if you get any output by executing rsync on your phone.
Open up a terminal and type "rsync --help" and see if it gives you output. If you get an error, the permissions might need to be reset or you may need to specify the full path.

The "backup" part in the rsync command "192.168.0.5::backup/" signifies the module name on the rsync 192.168.0.5 windows/cygwin rsync server.

This needs to be configured in the rsyncd.conf on your windows host using the rsync guide

Here's an example: 

[backup]

    path = /cygdrive/c/home/my_backups/phone
    comment = My phone backup
    read only = false



-Corey

Hussain

unread,
Jun 17, 2011, 3:39:51 AM6/17/11
to Tasker
Dear Corey,
After long hours of debugging, I finally managed to get it to work.
However, I was still unable to run rsync on my existing ROM (MIUI
1.6.10). Therefore, I flashed Cyanogen because they come with rsync
built in. Then, I just followed your guide, and voila my sync worked
great. And I am very happy with the way py script is executed because
it provide full error messages.
However, I just need to ask you a few more things:

1) Can you guide me on how I can use the rsync that's built in
cyanogen, extract it, craete an update.zip and flash it in cwr to my
MIUI rom?
2) Currently, my remote path is set to folder : 'cygwin/home/
phonebackup' This folder resides in my C drive which is also my system
partition. I was wondering if it is possible to use my other
partition(i.e. D:) as my remote location. If its possible, how do I do
it?
3) Since I can execute this script in tasker, can you also guide me
with how I can write a WOL (WAKE ON LAN) command in python so that I
can run following sequence in tasker:
i) Switch on WIFI (i can do this easily with tasker)
ii) WOL (wake my pc) : How do I do this using python script?
iii) Execute RSYNC

On Jun 17, 6:36 am, Corey Z <czua...@gmail.com> wrote:
> Before you execute the script, first try to see if you get any output by
> executing rsync on your phone.
> Open up a terminal and type "rsync --help" and see if it gives you output.
> If you get an error, the permissions might need to be reset or you may need
> to specify the full path.
>
> The "backup" part in the rsync command "192.168.0.5::backup/" signifies the
> module name on the rsync 192.168.0.5 windows/cygwin rsync server.
>
> This needs to be configured in the rsyncd.conf on your windows host using
> the rsync guide <http://www.gaztronics.net/rsync.php>.
>
> Here's an example:
>
> [backup]
>
>     path = /cygdrive/c/home/my_backups/phone
>     comment = My phone backup
>     read only = false
>
> *
> *
> -Corey

Corey Z

unread,
Jun 17, 2011, 9:56:13 AM6/17/11
to tas...@googlegroups.com
Hussain,

To setup a different path for the rsync module, all you would have to do is change it to "/cygdrive/d/backup" where "d" is the drive letter and "backup" is the target folder in the root of d.

As for an update.zip, those have never really been my specialty. I would probably post a Q/A on the xda forums for your phone asking for help. If you post in the right section, people are usually pretty helpful :P

As for WOL, there is actually a plugin that does just this on the market. There are a few, so you can also search for "locale wake on lan" for more options. I would also check to ensure you're connected to your WiFi before kicking this off.

Additionally, I am currently updating a plugin I've been developing on the side to include "run command" functionality that will actually log output/error streams to Tasker variables. When it's updated, I will let you know.

In the meantime, one thing to note about SL4A: If you ever run FixPermissions from ROM Manager, you will have to uninstall and reinstall the python module. The FixPermissions script screws with the permissions for this folder and makes everything break. (Yes, I learned this the hard way)

Best of luck,
Corey

Hussain

unread,
Jun 17, 2011, 1:40:05 PM6/17/11
to Tasker
Dear Corey,

Finally I managed to get the rsync binary to work on my current rom
(miui). This is what I did:
1) Extracted rsync binary from Cyanogen rom.
2) Using ADB, I ran following commands :
adb push rsync /sdcard/rsync
adb shell mount -o remount,rw /system
adb shell "cat /sdcard/rsync > /system/bin/rsync"
adb shell chmod 755 /system/bin/rsync
adb shell mount -o remount,ro /system
3) Now, my rsync is properly setup and works flawlessly.

Just a couple more question (sorry for disturbing you so many times):
1) Currently, the sync is only one way, i.e from local(android phone)
to remote (windows pc)
So, if I add any files in my remote folder, and then run the
script, the file gets deleted as it is not available in local(phone).
Is it possible for it to be 2way sync?
2) By using TASKER : Is it possible to copy the log created by sl4a,
use the write file command of tasker and write the log as txt to a
folder inside sdcard?(This will be useful for
checking purposes)

Again, thank you so much for all your effort in helping me.

On Jun 17, 9:56 pm, Corey Z <czua...@gmail.com> wrote:
> Hussain,
>
> To setup a different path for the rsync module, all you would have to do is
> change it to "/cygdrive/d/backup" where "d" is the drive letter and "backup"
> is the target folder in the root of d.
>
> As for an update.zip, those have never really been my specialty. I would
> probably post a Q/A on the xda forums <http://forum.xda-developers.com/> for
> your phone asking for help. If you post in the right section, people are
> usually pretty helpful :P
>
> As for WOL, there is actually a plugin<https://market.android.com/details?id=org.darune.autowakeonlan>that does just this on the market. There are a few, so you can also search

Corey Z

unread,
Jun 17, 2011, 2:52:19 PM6/17/11
to tas...@googlegroups.com
I'm glad you got it working. That's great news!

Unfortunately, I am under the impression that rsync is uni-directional. So, what you're trying to accomplish would be impossible using rsync.

The logs are found in the /sdcard/sl4a/ folder. For example, it would be rsync.py.log if you didn't rename the script. This file is stored in plain text. If you want to create a Tasker even that detects when the file is closed, you could do something on that event like read the file, etc. I haven't done much with reading files in Tasker but I know it's possible.

-Corey

Hussain

unread,
Jun 18, 2011, 1:42:20 AM6/18/11
to Tasker
Dear Corey,

Its fine if rsync is unidirectional. As long as my sdcard gets backed
up properly, im fine.

As for the rsync.py.log file, I think ill just use tasker to copy the
file to a new folder in my sdcard 'RSYNC LOGS', and rename the file to
corresponding date/time. That way, I keep all the log safe.

Again, I would really like to thank you for helping me throughout this
process.

If you happen to come to Malaysia for vacation, please let me know. :)
Reply all
Reply to author
Forward
0 new messages