deploymentlftp

Prevent downtime using lftp mirror


I'm using lftp to deploy a website via Travis CI. There is a build process before the deployment, for that reason a build directory is present and pushed to the root of the ftp server.

lftp $FTP_URL -e "glob -d mirror build . --reverse --delete-first --parallel=10 && exit"

It works quite well, but I dislike to have a downtime / temporary PHP parse errors because of missing files on my website. What is the best way to work arround that issue?


My first approach was an option to set a temporary directory, but the lftp man page says there is only a options for temporary files. I still tried the option but it didn't help.


My second approach was to use "mirror build temp" to use a temporary folder and then replace the root with it. The problem here is, that I cannot exclude the temp folder while deleting the old files and folders like rm -rf *.


Solution

  • This is a zero downtown pattern - each placeholder should be replaced:

    lftp $FTP_URL -e "mirror {SOURCE} {TARGET}-new-{TIMESTAMP} --reverse --delete-first;
    mv {TARGET} {TARGET}-old-{TIMESTAMP};
    mv {TARGET}-new-{TIMESTAMP} {TARGET};
    rm -rf {TARGET}-old-{TIMESTAMP};
    exit"