Backup of internal and SD storage via script (USB) tl;dr 


I want to backup my internal storage and SD card contents when connected via USB cable
due to potentially large amounts of data I don't want to use WiFi-based programs
failed attempt at using rsync and gvfs


Is there anything I can do?

Full story

I would like to backup data from my Android based phone (5.1.1 that is currently). I do not want to use an WiFi-based unstable and insecure hacky solutions with SSH and server here and client there (you name it - actually Samsung's very unreliable kies software made me think that way).   

By now I used a current Linux Mint (18.2), I tried to read data from the phone using rsync and the mapped storage from gvfs which failed miserably (permission issues, unstable connection).  

I would like to script which directories I backup and automate that process as far as possible. Can I make Android act as some sort of virtual device on Windows/Linux that allows some sort of file based access? Or a Web-DAV server connected via USB cable? No free cloud solutions (Google, OneDrive, Dropbox), either, please!

Thank you for your help.
As most of the time: error in layer 8 of OSI model. Here is what I did and what I should have done:

What I did

I mounted my target external drive using sudo (nothing wrong so far) and thus only root has permissions to write, rsync failed to do anything (which makes sense after all) - even when running using sudo.
Where exactly the error was, I am not absolutely sure, but let's focus on 

What I sould have done


Mount the external device using the GUI tools (for I am using an encrypted external drive)
Create a directory in the root of the external drive and chown it to your designated user (or group or both)
Run rsync


I created a small script to automate the finding of the gvfs path and rsync to external drive:

#!/bin/bash

PHONE_VENDOR=0000 # your phone vendor here!  
USERID=1 # your user ID here - possibly `id -u`

PHONE_BUS=\`echo $(lsusb -d ${PHONE_VENDOR}:) | cut -d' ' -f 2\`  
PHONE_BUS=${PHONE_BUS}%2C
PHONE_BUS=${PHONE_BUS}\`echo $(lsusb -d ${PHONE_VENDOR}:) | cut -d' ' -f 4 | cut -b 1-3` #extract vendor ID from lsusb  

SOURCEBASE=/run/${USERID}/gvfs/mtp\:host\=%5Busb%3A${PHONE_BUS}%5D
TARGETBASE= # your target base path here

rsync -a --progress ${SOURCEBASE} ${TARGETBASE}  # your rsync commands here


I don't know if anything changes (or this script works) when applying an fstab entry and then mounting via shell and not relying on the GUI tools.

This works for me and provides a neat way to backup contents from Android phones without copying whole SD-cards or internal spaces.

UPDATE - First real attempt

During execution rsync started throwing I/O-errors, probably because the process in general was taking very long (got about 50GB to sync). I am now starting over.
It might be a good idea to start a foundation by manually copying all files initially and all further syncing-processes by using rsync.

UPDATE - Second attempt

So it happens this amount might be too much for one attempt. Maybe this is my crappy smartphone, too. In general it works and after the first initial load-up it will be fine, I guess.