On my Android phone, I have:

  • A cron job to move files at 1:59am from /sdcard/WhatsApp/Media to /sdcard/wppmediabkp folder before WhatsApp backup at 2:00am:

mv -f /sdcard/WhatsApp/Media /sdcard/wppmediabkp

  • A cron job to move files at 2:30am back (from /sdcard/wppmediabkp to /sdcard/WhatsApp/Media):

mv -f /sdcard/wppmediabkp /sdcard/WhatsApp/Media

  • The "cron jobs" are tasks on "Tasks!" app (scheduling them with 00 59 1 ? * * and 00 30 2 ? * *). The commands are tested in Termux app also.


  • To exclude Media folder from backup, but to also restore image "link" to chats (to do not download again).

On restoration of wppmediabkp folder to /sdcard/WhatsApp/Media:

  1. Sometimes it works well (it creates the /sdcard/WhatsApp/Media with all its contents). It happens when /sdcard/WhatsApp/Media folder does not exist. For me, it is the expected behavior.
  2. Sometimes it creates a subfolder (/sdcard/WhatsApp/Media/wppmediabkp). It happens when /sdcard/WhatsApp/Media folder exists. For me, it is the issue - I would like to restore original folder tree, merging its contents.

I think it was reduced to a Unix issue, because I can use all Unix basic commands.

How to solve it (to get Media folder back merging its contents) using mv command?

  • With mv (and cp), when the target is a directory, the last element of each source path is copied into the target directory, so the restore command command should be mv -f /sdcard/wppmediabkp/Media /sdcard/WhatsApp/.
    – AFH
    Sep 15 '18 at 13:05

One approach is not to move directories. Let them exist all the time, move their content back and forth:

mv -f /sdcard/WhatsApp/Media/* /sdcard/wppmediabkp/
# and later
mv -f /sdcard/wppmediabkp/* /sdcard/WhatsApp/Media/


  • * will not match hidden files/directories;
  • with too many objects you may hit "argument list too long" error.

In case any of this is an issue, the solution should use something like find … -exec mv …. Either way move what is inside the directory, not the directory itself.

  • Excellent! Although Schedule! app does not work well, Termux shows that they are correct for desired backup operation.
    – kokbira
    Sep 15 '18 at 19:56

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.