Jump to content

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


Guest glossywhite

Recommended Posts

Guest glossywhite

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.

 

 

picsync.zip

Edited by glossywhite
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.