Auto backup for files

ElPeladoUriel

New member
Hi everyone,
I would like to create a macro which at a certain time every day, it searches for new images or videos in some specific folders, and if there are indeed any new images or videos, these are coppied to the SD card for backup...
Does anyone have something similar that I can edit or at least some base from where to start?
Thanks!
 

Dm114

Well-known member
Hi everyone,
I would like to create a macro which at a certain time every day, it searches for new images or videos in some specific folders, and if there are indeed any new images or videos, these are coppied to the SD card for backup...
Does anyone have something similar that I can edit or at least some base from where to start?
Thanks!
The first thing to do is to find a way to identify the "new" files. To do that, I'm sure that some Shell script command will give a list based on files timestamps. As I'm not familiar with these commands, many MD users will be able to help you on this field. You also could google by yourself...

Then, store the result in an array and iterate it to copy (or move) every identified file.
 

Quidn

Passionate Member
Hi everyone,
I would like to create a macro which at a certain time every day, it searches for new images or videos in some specific folders, and if there are indeed any new images or videos, these are coppied to the SD card for backup...
Does anyone have something similar that I can edit or at least some base from where to start?
Thanks!

I love MacroDroid a lot but not suitable for that purpose.
Could be done by shell command but likely not to be robust. Moreover that'll need you to study and test a lot.

I'd recommend FolderSync (Pro) which tailored for that purpose and able to be commanded by MacroDroid.
 

Dm114

Well-known member
I love MacroDroid a lot but not suitable for that purpose.
Could be done by shell command but likely not to be robust. Moreover that'll need you to study and test a lot.

I'd recommend FolderSync (Pro) which tailored for that purpose and able to be commanded by MacroDroid.
I can't agree with you when you say MD is not suitable for that purpose and don't understand why you say it won't be "robust"...

You're probably right when saying that some other external apps could solve @ElPeladoUriel's problem, but they soon will be limited if he wants to sophisticate his macro later. Moreover, it seems that the app you recommend only works to/from the cloud (unless I missed an explanation).

On a personal point of vue, I feel it's a bit unfair to promote external apps here on this forum (specifically dedicated to MD) when MD can do the job (mainly so easily in this case). The user maybe wants to unify the job he wants to do on his device using as few external apps as possible and use MD as often as possible.

Have a nice day (or evening) and... enjoy MD! 😉
 

Dimlos

Well-known member
I think you should put your question in Help and Troubleshooting.
There is a command called rsync in linux, but unfortunately it doesn't work with MD's shell script.
You can do it with Termux, but it is not easy.
FolderSync is easier, but if you want to try it even with Termux, I will explain it when I have time.
 

Quidn

Passionate Member
I can't agree with you when you say MD is not suitable for that purpose
I will do respect your opinion. But I'd say suitableness is relative concept, and that's why I fully respect your disagreement.

I think MacroDroid is the most versatile Android application in the Play Store ever. No doubt. No need to prepend "one of".
Definitely some people wouldn't agree by comparing to Tasker, but I can proudly say that MacroDroid is on the top.

And this doesn't mean MacroDroid is just suitable enough to any purposes to everyone.


and don't understand why you say it won't be "robust"...
Backup may quite simple job, but difficulty goes up exponentially when start to say about robustness.

It'd be a very very long story but in short...
  • Unless it's a carefully written system component, no matter what the app is, executing shell command on Android for long time in background by highly stable never goes easy.
  • Even if stdout seems the command was successfully done, integrity is yet another problem.
  • Believe me, I don't say in assertively unless I have way more than enough data to conclude.
  • And I believe, anyone who can handle all of these never easily suggest to try in situation like this.
  • I'm not talking about sort of "NASA-grade" reliability. Even I have experience of facing all of these problems.


but they soon will be limited if he wants to sophisticate his macro later.
I don't understand what you imagine. They are just too different kind of applications and even I said using both together will be more effective.
However, please tell me some scenario you can thought. I'll give you very detailed and correct answer.


Moreover, it seems that the app you recommend only works to/from the cloud (unless I missed an explanation).
I don't know you think me that I'm an idiot who blinded to promote a foreign application, but please don't worry, you were wrong.
  • The goal of OP was to backup to (external) SD
  • I recommended an application
  • Then it would and should support local backup
In fact, even internal to internal or external to external, any combination would be supported.


(unless I missed an explanation)
This was also wrong. To be correct, what you missed actually was that any explanation of any application may not describe all of its features.


I feel it's a bit unfair to promote external apps here on this forum (specifically dedicated to MD)
I wonder that if you really felt as "promote" that.

Again, I'd respect your opinion, but please read the context again and let me know if that still looks as promote, rather than recommend, introduce, refer, advise, or any other.


when MD can do the job (mainly so easily in this case).
Actually almost any job could be done by MacroDroid. As you can see in my previous postings, I often suggest existed MacroDroid feature as a solution.

In your perspective, no other application could be recommended and everyone just have to competite who's more inefficient and unpractical. Feature requests and bug reports? I can say most features could be implemented in current version and most bugs would be avoided.

There's nothing truly impossible if any other third party application in Play Store could do so. If you can imagine something impossible by MacroDroid, then I'll explain how to do that by MacroDroid. Even PoC would be easy enough, but again, difficulty goes up exponentially when start to say about robustness.


(mainly so easily in this case).
I wonder how could you say that assertively.
I already know how to do this and have enough experience, but I never could say "so easily", especially for "in this case".
As I'm not familiar with these commands, many MD users will be able to help you on this field. You also could google by yourself...
Even you didn't(couldn't because you don't know either) provide any realistic help and just criticizing(or blaming). Hmm...
How it could be so easy to you?


The user maybe wants to unify the job he wants to do on his device
Of course there's possibility, but I don't think that could be a proper reason of your disagreement.
Because that logic could applied same in opposite, like this: "The user maybe wanted to find the most easy and efficient way even more and more applications are needed"





Anyway.

Whatever it was promote or recommendation or introduce, I'll think about your feedback sincerely.

I think it would been way more effective if you just mentioned about referring(or "promoting") foreign app, but now it's getting farer from its topic.

I still respect your opinion and nothing personal, just wanted to correct wrongnesses.
 

dhj49er

Well-known member
I can't agree with you when you say MD is not suitable for that purpose and don't understand why you say it won't be "robust"...

You're probably right when saying that some other external apps could solve @ElPeladoUriel's problem, but they soon will be limited if he wants to sophisticate his macro later. Moreover, it seems that the app you recommend only works to/from the cloud (unless I missed an explanation).

On a personal point of vue, I feel it's a bit unfair to promote external apps here on this forum (specifically dedicated to MD) when MD can do the job (mainly so easily in this case). The user maybe wants to unify the job he wants to do on his device using as few external apps as possible and use MD as often as possible.

Have a nice day (or evening) and... enjoy MD! 😉

I use Foldersync pro for backup.

It can copy files an folders to and from
SD Card
USB drive
Your own NAS
as well as many Cloud providers.

I find it easy to set up and have configured macros to initiate the sync operation.

For example inserting a specific usb drive will trigger syncing folders to the drive, performing an automatic backup.
 

sampleuserhere

Active member
A simple command cp -rn might do the job. It copies the directory as whole while skipping existing files. Run the following with Shell Script action, check out use helper app.

Code:
monitor="monitored folder"
target="target folder"
cp -rn "$monitor" "$target"
 
Last edited:

Dimlos

Well-known member
@sampleuserhere
In the case of the cp command, -n option will not overwrite any updated files with the same name.
Without -a option, I think the timestamp will be updated.
Also, in the case of rsync, it is a differential copy, which is advantageous when the number of files increases on a slow SD card.
 

Dimlos

Well-known member
Termux is not as difficult as it sounds, so why not try FolderSync first and then challenge again?
rsync [options] source destination
 

Dm114

Well-known member
I will do respect your opinion. But I'd say suitableness is relative concept, and that's why I fully respect your disagreement.

I think MacroDroid is the most versatile Android application in the Play Store ever. No doubt. No need to prepend "one of".
Definitely some people wouldn't agree by comparing to Tasker, but I can proudly say that MacroDroid is on the top.

And this doesn't mean MacroDroid is just suitable enough to any purposes to everyone.



Backup may quite simple job, but difficulty goes up exponentially when start to say about robustness.

It'd be a very very long story but in short...
  • Unless it's a carefully written system component, no matter what the app is, executing shell command on Android for long time in background by highly stable never goes easy.
  • Even if stdout seems the command was successfully done, integrity is yet another problem.
  • Believe me, I don't say in assertively unless I have way more than enough data to conclude.
  • And I believe, anyone who can handle all of these never easily suggest to try in situation like this.
  • I'm not talking about sort of "NASA-grade" reliability. Even I have experience of facing all of these problems.



I don't understand what you imagine. They are just too different kind of applications and even I said using both together will be more effective.
However, please tell me some scenario you can thought. I'll give you very detailed and correct answer.



I don't know you think me that I'm an idiot who blinded to promote a foreign application, but please don't worry, you were wrong.
  • The goal of OP was to backup to (external) SD
  • I recommended an application
  • Then it would and should support local backup
In fact, even internal to internal or external to external, any combination would be supported.



This was also wrong. To be correct, what you missed actually was that any explanation of any application may not describe all of its features.



I wonder that if you really felt as "promote" that.

Again, I'd respect your opinion, but please read the context again and let me know if that still looks as promote, rather than recommend, introduce, refer, advise, or any other.



Actually almost any job could be done by MacroDroid. As you can see in my previous postings, I often suggest existed MacroDroid feature as a solution.

In your perspective, no other application could be recommended and everyone just have to competite who's more inefficient and unpractical. Feature requests and bug reports? I can say most features could be implemented in current version and most bugs would be avoided.

There's nothing truly impossible if any other third party application in Play Store could do so. If you can imagine something impossible by MacroDroid, then I'll explain how to do that by MacroDroid. Even PoC would be easy enough, but again, difficulty goes up exponentially when start to say about robustness.



I wonder how could you say that assertively.
I already know how to do this and have enough experience, but I never could say "so easily", especially for "in this case".

Even you didn't(couldn't because you don't know either) provide any realistic help and just criticizing(or blaming). Hmm...
How it could be so easy to you?



Of course there's possibility, but I don't think that could be a proper reason of your disagreement.
Because that logic could applied same in opposite, like this: "The user maybe wanted to find the most easy and efficient way even more and more applications are needed"





Anyway.

Whatever it was promote or recommendation or introduce, I'll think about your feedback sincerely.

I think it would been way more effective if you just mentioned about referring(or "promoting") foreign app, but now it's getting farer from its topic.

I still respect your opinion and nothing personal, just wanted to correct wrongnesses.
I didn't want to get into an argument with you in any way, but I found your comments a little surprising for a new user who had only registered a few weeks ago...

I respect and agree with most of your explanations and you seem, indeed, to greatly appreciate MD. But you have probably noticed, like some of us, that, recently, some users have tended to denigrate MD very unfairly...

I will not go any further in this exchange of ideas because I think we finally understand each other.
 

sampleuserhere

Active member
@sampleuserhere
In the case of the cp command, -n option will not overwrite any updated files with the same name.
Without -a option, I think the timestamp will be updated.
Also, in the case of rsync, it is a differential copy, which is advantageous when the number of files increases on a slow SD card.

I didn't know about a, I'm not that well versed yet with the options so I had to check again. It seems that there is u option as well if OP wants to copy newer files. It would be closer to a sync instead of a backup though.

I'd say it's better to start small and let the experience teaches him the lesson. Let's say that OP couldn't compensate with the technical circumstances he may realize later, then he always has the room to use the other tools.
 

Dimlos

Well-known member
The appeal of MD is that it can be used without any code, so deep knowledge of scripting may not be necessary.
At first, it is a good idea to check the operation with directories and files that will not cause any problems even if they disappear.

However, since the OP hasn't posted, it may not be the answer he wants, or he may not be able to follow the conversation.
 

sampleuserhere

Active member
Well who knows, there wasn't much details given either. I was reluctant to go into details and provided a solution with the least technical requirements instead.
 

Quidn

Passionate Member
I didn't know about a, I'm not that well versed yet with the options so I had to check again. It seems that there is u option as well if OP wants to copy newer files. It would be closer to a sync instead of a backup though.

I'd say it's better to start small and let the experience teaches him the lesson. Let's say that OP couldn't compensate with the technical circumstances he may realize later, then he always has the room to use the other tools.
Well who knows, there wasn't much details given either. I was reluctant to go into details and provided a solution with the least technical requirements instead.

Come on... Can't we say just realistic and practical things, please?

I fully agree that give opportunity to stack experience by oneself are very important, but that kind of teaching must be done by someone knows how to do that properly. cp -rn? Oh no, no... I don't know where I start to say.

If where we are was a forum about RPi, NAS, server, or anything have complete standard CLI interface, then approach like that makes sense and will helpful to study. But no, in Android, no. Whatever how many options are appended to cp, no. Even in general Linux like Debian or Fedora, just by cp? No.
What if you already knew where the mtime would be placed, and has been a guru to filtering files by mtime? Of course never enough yet and you wouldn't catch some newly copied files. After you have mastered how to catch all of newly added files? Well, that'd be a good start!

I had written about 500 lines of shell script just for do that. It have been working very well for years in environment where rsync or similar couldn't be used, but I had to spend pretty much time to do chaos-testing and fixing to handle any kind of exceptions.
And I really doubt if same approach would been work robustly in Android too, especially for mobile device, even invest 10x more time I had to spent to achieve above.

Most importantly, consuming time to handle another and yet another problems specific to certain device or current firmware or caused by just characteristic of Android would never much helpful, I believe.
Android is, especially recent versions, not intended to be used like that and using shell command must be avoided when possible. Violating official guideline never could be recommended.

I strongly believe that the reason of some people could say that'd be possible or even easy by shell commands is just they haven't experienced and also don't have any idea yet how to do that properly.

Enforcing(or inducing) to use unnecessary shell commands would results many users to give up to use and leave MacroDroid and/or this forum. Please don't rising up the barrier. I ask to let any users to come through.



I'd say it's better to start small and let the experience teaches him the lesson. Let's say that OP couldn't compensate with the technical circumstances he may realize later, then he always has the room to use the other tools.

What do you think how many begginers would clearly realize that a small single mistake could results both of origin and backup to be gone and then aware to be prepare duplicated backup and test bed are crucially needed to them?

We should be very conservative when talking about backup. Whole different problem. Experimental attempts never recommended and especially for beginners.
 

sampleuserhere

Active member
Well thanks for pointing all of that, I was just saying based on what I have used so far. I only ever does local backup too with a simple rsync option (via termux), mv and cp.

Fortunately we have you here now, who is down elobarating every possible details here. I appreciate that, OP will definitely find it useful. @Quidn 👍
 

Dimlos

Well-known member
Certainly FolderSync is appropriate in this case, but I don't think you have to dismiss shell scripts in general.

Shell scripts can be found in MD actions, and if you are just writing a small script while looking things up on the Internet, you won't have much of a problem.

However, if you try to do something elaborate, you may find that some commands or options are omitted or don't work.

But even in such cases, you can usually get around it by using the Termux:Tasker plugin and Termux, and it offers more possibilities than just selecting an action from the menu.

If you use them in the right places, you can use MD in a more advanced way, so it is a good idea to try your hand at it when you get used to it.
 

Quidn

Passionate Member
I didn't want to get into an argument with you in any way, but I found your comments a little surprising for a new user who had only registered a few weeks ago...

I respect and agree with most of your explanations and you seem, indeed, to greatly appreciate MD. But you have probably noticed, like some of us, that, recently, some users have tended to denigrate MD very unfairly...

I will not go any further in this exchange of ideas because I think we finally understand each other.
Actually, a week. ;) Forgive me I corrected your word again. :ROFLMAO:
It seems that my first reply was possible to misleads. At that time I didn't have much time and what I wrote wasn't hide that.
I appreciate for your understanding I see what your concern now.



Well thanks for pointing all of that, I was just saying based on what I have used so far. I only ever does local backup too with a simple rsync option (via termux), mv and cp.

Fortunately we have you here now, who is down elobarating every possible details here. I appreciate that, OP will definitely find it useful. @Quidn 👍
I appreciate for your understanding, too.
And thank you for accept my straightforward opinions.



I don't think you have to dismiss shell scripts in general.
This may correct, and that's why I bolded "unnecessary" in my last reply, which quoted below.
Enforcing(or inducing) to use unnecessary shell commands would results many users to give up to use and leave MacroDroid and/or this forum. Please don't rising up the barrier. I ask to let any users to come through.



If you use them in the right places, you can use MD in a more advanced way, so it is a good idea to try your hand at it when you get used to it.
Also, that's why I have pretty much experiences of running shell commands.
Even though, I don't positively recommend to use shell commands except for something hard to be done by other methods.
Violating official guideline never could be recommended.
 

ElPeladoUriel

New member
(OP here)
WOW, didn't expect a heated conversation when I posted this
So first, thanks everyone for trying to help. The reason I didn't come back was that I didn't get any notice that you all replied to me :)

I do have some experience with code and linux, so I may try some of your suggestions here, but as some of you also said, I think I will try to use FolderSync first to see if it does what I want to do. If it does I may create a macro to run it.
Basically, it is for backing up images and videos from my daughter's phone, to the SD card. the phone itself is not so stable lately and I don't want her to loose to many of her files if it dies one day. and I prefer to copy and not move the files to the SD because SDs also may day any day

So again, thanks everyone. I 'll be back here if I need some more help from you!
 
Top