Anyone Using Rsync with Android? Looking for a no clobber feature

Edit: I got this to work. Solution is below and on the tutorial section.

I xfer files daily to and from my phone via scripted ftp. While it works, I would like to have a no clobber option such as is common in rsync. Does any one have a linux to android rsync solution? or an ftp no clobber solution?

I would suggest Syncthing, and then experiment with either side of the particular sync share being set to “Send & Receive” (the default), or “Send Only”, or “Receive Only”. In this way, you might achieve the “no-clobber” goodness you’re after.

1 Like

Prep work:

  1. Have your phone connected to your LAN - WIFI on
  2. Have the app SimpleSSHD installed on your phone and running

On the Phone

  1. Open SimpleSSHD and go to settings via the kabab menu
  2. Note the Port Number
    • In my case it was set to 2222
  3. Note (write down) the SSH Path
    • in my case it was /data/user/0/org.galexander.sshd/files
  4. Set the Home Directory to: sdcard
  5. Return to the main screen of SimpleSSHD
  6. Note the ip address of the phone on the main screen of SimpleSSHD
    • in my case it was 192.168.1.112

On your computer

  1. Open a terminal
  2. ssh into your phone using the port and ip address from above
    • ssh -p 2222 192.168.1.112
  3. When prompted to allow this connection, type: yes and hit enter

On the phone

  1. On the main screen of SimpleSSHD a single-use password is displayed

On your computer

  1. Enter the password that is displayed on SimpleSSHD
  2. You are now logged in to your phone via an ssh terminal. Have a look around with ls -l and cd and note the directory structure.
    • in my case the photos are located (starting at sdcard) in DCIM/Camera
  3. Type exit [enter] to end the ssh session
  4. Confirm the existence of your public ssh key on your computer with
    • cat ~/.ssh/id_rsa.pub
  5. If the key was not found, generate one with
    • ssh-keygen -t rsa -b 4096
    • accept the prompt for location
    • don’t use a password – leave blank
    • do #16 again
  6. Add the port 2222 for the phone’s ip address to your ssh config file with these commands:
    • echo “Host [ip addres of the phone]” >> ~/.ssh/config
      • echo “Host 192.168.1.112” >> ~/.ssh/config
    • echo “Port [port of the phone]” >> ~/.ssh/config
      • echo “Port 2222” >> ~/.ssh/config
  7. Copy your id_rsa.pub key to the phone using secure copy with
    • scp ~/.ssh/id_rsa.pub [ip address of the phone]:[ssh path on the phone]/authorized_keys
    • in my case it was:
      • scp ~/.ssh/id_rsa.pub 192.168.1.112:/data/user/0/org.galexander.sshd/files/authorized_keys

On the phone

  1. SimpleSSHD now displays a newly generated, single-use password

On your computer

  1. Enter the password that is displayed on SimpleSSHD
  2. You should now be able to login to your phone with
    • ssh 192.168.1.112

rsync command to copy pictures from your phone

  1. rsync --verbose --ignore-existing --dry-run 192.168.1.112:DCIM/Camera/* ~/Pictures
    • #23 is with the --dry-run option. No action is actually performed
  2. rsync --verbose --ignore-existing 192.168.1.112:DCIM/Camera/* ~/Pictures

rsync command to push audio files to your phone

  1. rsync --verbose --ignore-existing --dry-run ~/path/to/my/audio/* 192.168.1.112:DCIM/Music
    • #25 is with the --dry-run option. No action is actually performed
  2. rsync --verbose --ignore-existing ~/path/to/my/audio/* 192.168.1.112:DCIM/Music

Here is how I am using this.

I set the SimpleSSHD app to be fired by Tasker (Android scheduling app) every morning. I set a cron event on my computer to grab my new pictures from my phone. I set another cron event on my computer to push my new podcasts that were aggregated (while I slept) onto my phone for listening during the following day. (I scripted a personal aggregator for privacy and post processing reasons).

1 Like

Warrior

1 Like

Well, you did it your way, and I admire your persistence, however your procedure took 26 steps! I can’t praise it as elegant.

1 Like

LOL - very true. But there are 26 steps because I painstakingly detailed every element for the noobie. For me, the gem here is that I never have to take any of those steps again.

1 Like

I have to second what @esbeeb stated that Syncthing is the way to go for this task. I use it for synchronizing pictures between my mobile and my Desktop Linux machines. I have been using it regularly for years and much prefer it to the Google Drive equivalents. I have my phone paired with 3 different machines directly to ensure that there is always a machine available to dump the pictures.

I also have a sync folder that I keep documents I want to be able to view on my phone or my computer. This works fantastically well too. Though, I can say, as of recent, I don’t use it much on the phone as I do on a tablet.

1 Like