Sometimes, I like to back up my photos and videos from my Android device to my Mac manually. Sure, I have Google Photos backup photos to the cloud, but having a local backup is also useful. I use ADB to copy files from my Pixel 8 Pro to my Mac. However, ADB doesn’t have a easy way to backup only newer files, so I had to find my own solution.
In the past, I’ve used the adb pull command to easily backup photos, but this method can take ages when you have hundreds of files on the device. The following command does not ignore existing files on the destination:
adb pull -p -a /storage/self/primary/DCIM/Camera/ ~/Camera
So, I came up with a solution using a shell script and the same command above. The script assumes you already have ADB setup and configured on your system.
The script (found below) first gets a list of files I want to copy from the device folder and writes this to a file (file_list.txt
). I then filter the files in the temp file to only give me the filetypes (or even prefix) that I want and write the list of files to another file (files_to_pull.txt
, this file now contains only the full filenames that need to be copied, and not the other information from the ls -l
command).
Then, we loop through each line in the file and check if the file already exists in the destination folder. If the file does not exist, adb pull
is used to copy the file from the device to the destination.
You can easily change the device path and destination by editing Lines 2 and 5 in the code above. If you need to filter other filetypes or a different patten entirely, you can edit line 11. I wouldn’t edit anything else unless you understand the code.