Jump to content


Photo

Simple photo & video backup bash script for OTG flash media (rsync) needs root


  • Please log in to reply
No replies to this topic

#1
glossywhite

glossywhite

    Hardcore

  • Members
  • PipPipPipPipPipPip
  • 1,896 posts

Here's a simple bash script I've just written which, when executed via "Terminal Emulator" (or adb shell), backs up ALL Photos and videos found under /sdcard/DCIM to an inserted OTG USB flash drive/SD card reader etc.

1/ Download zip file

 

2/ Extract it

 

3/ Go into extracted DIR, and (in Windows) shift & right-click >> "Open command window here"

 

4/ Connect to your Moto G using ADB or ADB WiFi etc

 

5/ Run these commands in the command window which just opened  - YOU NEED Moto G ADB drivers and ADB installed (press enter at the end of each line, run one line at a time, in order, starting at the top line):

adb push rsync /sdcard/rsync
adb push picsync /sdcard/picsync
adb shell
su 
mount -o remount rw /system
cp /sdcard/rsync /system/bin
cp /sdcard/picsync /system/bin
chmod 755 /system/bin/rsync
chmod 755 /system/bin/picsync
mount -o remount r /system

6/ Create a folder named "Camera" in the flash drive/SD card you wish to use to backup your photos & videos to, otherwise the script won't work.

 

7/ Plug in the flash drive etc to the micro USB port at the base of the Moto G

8/ Once it's mounted (give it 15 secs to be sure), open a terminal emulator and run as root:

 

picsync

Your photos and videos will proceed to be backed up to the "Camera" folder you created on the external media. This script will backup ALL media the first time around, and from then on, ONLY backup photos and videos that have been captured since the last time you backed up, instead of re-copying EVERYTHING again each time (which would be nuts!).

I hope you enjoy this script. I cannot offer any tech support of any kind, and please use at your own risk (there is no risk - see the source below):

#!/system/bin/sh
if [ -d "/mnt/media_rw/usbdisk/Camera" ]; then
echo "Syncing media now..."
rsync -av --ignore-existing /sdcard/DCIM/Camera /mnt/media_rw/usbdisk/
else 
echo "Please insert the backup drive, then run this script"
exit
fi

I happen to know this technique also works over ssh via WiFi to a server, as I backup this way too. However, I wanted to make this as newcomer friendly as possible, so didn't over-complicate things by adding that in also. Feel free to modify this and hack away as much as you wish :)

You may see some error messages right at the end; I think this is to do with it not being able to copy thumbnails or some kind of hidden files, but ALL photos and videos copy perfectly. If I get time and I find out how to fix that, I shall do.

 

 

Thank you :)

Matt.

 

 

Attached File  picsync.zip   454.29KB   3 downloads


Edited by glossywhite, 14 June 2014 - 09:03 PM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users