google-drive-apigoogle-cloud-storagestoragegoogle-drive-shared-driveflysystem-google-drive

sync google drive folder algorithm


let say the source folder is Folder A. The target folder is Folder B.

Each time period (maybe 1 day), delete folder B and I use programming copy Folder A to Folder B using recursion.

I am doing this since this is the most simple way.

But this method is stupid, since each time the folder B is deleted.

Is there any way we just alter the target folder a little bit if there is only a minor change in folder A?


Solution

  • If I understand you correctly you have a main folder A with some files in it. These files may or may change over the course of the day. Once a day you want to backup everything that is in folder A to folder B.

    Your current method off attack to solve this issue is to simply delete folder B every day and copy everything from A into B.

    I agree this is the simplest option and I really don't see any issue with it assuming that is that there are not a large number of files or large files which can be time consuming to copy.

    check for changes.

    What you could do when you request the files in Folder A is check the modifiedTime on the file. It should show you the last time the file was changed. If the file hasnt been changed since the last time you did your backup then there is no reason to copy it to folder b. If it has changed then you delete that file from folder B and copy the new one in.

    "modifiedTime": "2021-08-13T06:39:56.708Z",

    Now this does not take into account new files which have been created in folder A nor does it take into account files which may have been deleted from folder A.

    For that you will need to do a file.list and compare what you have currently in A and b. If A has files that B doesn't well then they are new files and you need to copy them in if A is missing some files that appear in B well then they were deleted you should delete them from B.

    Would i bother.

    In my opinion unless we are taking about more then say 200 files or the files are bigger then 10 mb I don't think i would bother changing what you have now. While i agree checking would be a more elegant solution the question comes into play is it worth it in the end if you are only copying 10 files.