Tuesday, March 8, 2016

How to pull only newer files with “adb pull”? (Android SDK utility)


With the command "adb pull /sdcard/" I can copy all the contents of the internal memory of my Android phone into my current local directory (and "adb pull /mnt/extSdCard/" does the same with the external SD card). But that command always copies everything, even files I already have stored locally.


Is there any way to copy only new and modified files? (files with a newer date)



Answer



As described by ss-3-1415926535897932384626433 there is no flag, but you have to get a list of files first and then check if your local files match. I wrote a little script for it:


#!/bin/sh

rfolder=/sdcard/DCIM/Camera
lfolder=Camera


adb shell ls "$rfolder" > android.files

ls -1 "$lfolder" > local.files

rm -f update.files
touch update.files

while IFS= read -r q; do
# Remove non-printable characters (are not visible on console)

l=$(echo ${q} | sed 's/[^[:print:]]//')
# Populate files to update
if ! grep -q "$l" local.files; then
echo "$l" >> update.files
fi
done < android.files

script_dir=$(pwd)
cd $lfolder


while IFS= read -r q; do
# Remove non-printable characters (are not visible on console)
l=$(echo ${q} | sed 's/[^[:print:]]//')
echo "Get file: $l"
adb pull "$rfolder/$l"
done < "${script_dir}"/update.files

Adjust the remote folder rfolder and the local folder lfolder to locations of your own choice.


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...