Refresh FTP without the file being removed while replacing

2

FTP whenever you send a file it is unusable for a few milliseconds, until the whole file is in place. The problem with this is that the file for a few milliseconds does not exist or is corrupted, which causes include() files to stop working for a few moments.

Is there any way to update a file and how does it recover a backup DURING THESE "milliseconds"?

I thought of a solution , but I do not have much knowledge to do this and I did not know what to do, and I believe there should already be some solution, it is not possible that only I have this problem !

nginx / php-fpm says, for example:

Call to undefined function minha_funcao()

This occurs during these few minutes that the file is replaced, but that is enough to fill the logs and also enough to lose visits.

My idea would be to have some backup.

If "include.php" does not exist then get from "backup / include.php". When you finish submitting the "include.php", then copy the "include.php" (which has no problem copy) and send it to the "backup / include.php" (which no one is using now).

However, I have not the slightest idea of:

  • How to move files by checking that they are not being used (perhaps by the modification date? More ...)

  • E ....

    Is there any software that already does this?

        
    asked by anonymous 29.08.2016 / 18:42

    1 answer

    1

    Normally the changes are made with the system paused, without executions. Because often an update can also modify the database, authentication rules, etc. So in these more critical cases, it is more recommended to interrupt all hits.

    Alternatively, for minor cases where you do not necessarily need to overturn any connections, you could create a mirror of that system within the same server. So I would always do the updates on the "mirror" that is "sleeping".

    DocumentRoot Technique

    Example, in Apache the original site is in the directory

    /www/site/
    

    The mirror, that is, an exact copy of all these files from the original is in another folder

    /www/mirror/site/
    

    Suppose at this point the site is running with 200 concurrent connections and you do not have loadbalance or anything. All you have is one server. So you have to deal with what you have.

    You need to update 200 files, but without interrupting anything or causing data corruption.

    So what you could do is update the files in the mirror directory

    /www/mirror/site/
    

    When complete, go to Apache and change the DocumentRoot to the location of the mirror

    <VirtualHost 127.0.0.1:80>
    #DocumentRoot "/www/site/"
    DocumentRoot "/www/mirror/site/"
    </VirtualHost>
    

    Save the change and give a reload or restart.
    The site will now be running under the system with the updated files.

    This is just one of several techniques and has points to observe as possible conflict with some other system that is depending on the original location of DocumentRoot . There may also be some loss of cache data. But they are usually small losses that recover in the first executions. Just be aware of dependencies that can cause conflicts, but in an environment in normal conditions, have no problems.

    Note that there will also be a loss of connections due to restarting Apache.

    DirectoryIndex Technique

    Another less invasive mode that follows the same logic of document root swapping is to do this by changing only the htaccess . But this will depend on how the system files are structured. If it is well organized you can do the same scheme mentioned above, but using only htaccess , without restarting Apache.

    Logic is simple, typically the system only has the index.php file in the public folder. You can have a second file, let's call it foo.php .

    In htaccess , just change DirectoryIndex to that other foo.php file. The foo.php file includes mirror directory files.

    All you need to do is follow the same logic as the virtualhost example, except that instead of moving directly to Apache, you would only change DiretoryIndex . A simple htaccess upload would already be swapping from one directory to another.

    And so you follow in turn. In the next update, you make changes to the directory that is "sleeping".

    obs: In the examples I used Apache and PHP because they are more popular but can be applied in any other environment.

        
    29.08.2016 / 19:17