5

adb push seems to push everything into the dest folder regardless of their changed/unchanged states. So it wastes a lot of time. Is it possible to sync rather than copy (i.e. to rsync rather than cp)?

I see adb has a sync option, but I'm not quite sure whether it's relevant or not.

2

While this answer is not exactly an explanation on the usage of adb sync, it may help when your primary goal is to sync files using adb.

You may be interested in adb-sync which is a Python script that uses adb to synchronize files from your computer to your Android device or vice versa.

Example (computer -> device):

adb-sync /home/abc/ /sdcard/abc

Example (computer <- device):

adb-sync --reverse /sdcard/abc /home/abc/ 

If missing files on the source should be deleted on the target you have to specify --delete.

2

You would use adb push --sync, for example:

adb push --sync /home/abc/ /sdcard/abc

from adb --help:

file transfer:
 push [--sync] LOCAL... REMOTE
     copy local files/directories to device
     --sync: only push files that are newer on the host than the device

but it seems that this function is available for relative newer ADB version such as version 1.0.40.

0

When running adb without any commands, you get a list of possible commands, and here it is:

adb sync [ <directory> ]     - copy host->device only if changed
                             (see 'adb help all')

Looks pretty relevant to me :)

  • 3
    Would you please give an example on how to use this? Say if I want to sync /home/abc/ on PC to /sdcard/abc/ on device. – Cyker Sep 23 '12 at 5:58
  • Did you try adb help all? – pzkpfw Sep 24 '12 at 8:36
  • 3
    Yes. It can sync system/data partition. But I just want to sync one folder on sdcard. Do you know how to do that? – Cyker Sep 24 '12 at 20:22
  • It is not implemented in version <= 1.0.31. – echo Jan 29 '13 at 1:26
  • While this command looks promising at first, I couldn't get it to work after a quick try. A real example as requested by cyker would be helpful. – Flow Apr 17 '14 at 18:48
0

I have made a python script that works like charm for windows.
It copies all the files from the current folder to the device(path can be edited in the code) except the files already present there.
Optionally, -l switch can be used to list the files with copy size before actual copy.

import os
import subprocess
import sys
files=os.listdir('.')
files=set(files)
devPath="/path/on/adb/device"
cmd="adb shell ls -a " + devPath 
deviceFiles=subprocess.check_output(cmd,shell=True).decode().split('\r\r\n')
deviceFiles=set(deviceFiles)
filesToCopy=files-deviceFiles
size=0
count=0
justList=False
if (len(sys.argv)>1 and sys.argv[1]=='-l'):
    justList=True
for f in filesToCopy:
    count+=1
    size+=os.path.getsize(f)
    if(not justList):
        cmd="adb push "+str(f)+" "+devPath+str(f)
        os.system(cmd)
    print(str(count) + ' ' + str(f))
if(not justList):
    os.system("adb shell rm "+str(devPath)+"/"+sys.argv[0])
print(str(size/1000000) + " Mb")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.