You should use a different deploy process, we currently use Fabric, it creates symlinks for certain folders so you could go back to the previous version and the shop is set to maintenance for a very small amount of time. I would recommend deploying within the hour that the shop has just a few users.
More information about fabric.
Our deploy task, this might help you:
Sorry for editing the other answer:
@task
def deploy():
print('Deploying ' + colors.blue(env.git_branch) + ' branch to ' + colors.blue(env.name) + ' environment at ' + colors.blue(env.domain) + ' on path ' + colors.blue(env.deploy_to))
if not confirm('Continue?', default=False):
return
notify(':loudspeaker: _%s_ started deploying the *%s* branch to the *%s* environment at %s :metal:' % (env.local_user, env.git_branch, env.name, env.domain))
try:
if files.exists(env.release_dir):
error('"%s" directory already exists!' % env.release_dir)
check_for_clean_current_dir()
update_repo_dir()
check_or_create_shared_files(create=False)
run('mkdir -p "%s"' % env.release_dir)
run('git clone "%s" "%s"' % (env.repo_dir, env.release_dir))
symlink_shared_files_into_release()
with cd(env.release_dir):
run('tools/composer.phar install --prefer-dist --no-dev')
run('npm install --production')
cleanup_files_after_installation()
run('git checkout pub/.htaccess')
run('php bin/magento deploy:mode:set --skip-compilation production')
run('php bin/magento setup:di:compile')
run('touch pub/static/deployed_version.txt') # workaround for new bug/feature introduced in M2.1.1, keep in here until https://github.com/magento/magento2/issues/6426 is fixed
run('php bin/magento setup:static-content:deploy %s %s' % (' '.join(['--theme %s' % t for t in conf.adminhtml_themes]), ' '.join(conf.adminhtml_languages)))
run('php bin/magento setup:static-content:deploy %s %s' % (' '.join(['--theme %s' % t for t in conf.frontend_themes]), ' '.join(conf.frontend_languages)))
run('php bin/magento maintenance:enable')
fix_file_permissions()
timestamp_before_going_down = time.time()
symlink_new_release_to_current()
warn('\n!! MAINTENANCE MODE ENABLED - WEBSHOP IS DOWN !!\n')
with cd(env.current_dir):
run('php bin/magento setup:upgrade --keep-generated')
local('curl --silent --insecure %sopcache_clear.php?%s' % (env.domain, urllib.urlencode({'secret': conf.opcache_secret})))
run('php bin/magento maintenance:disable')
run('php bin/magento cache:flush') # there are reports from colleagues that indicate we need to run this, even though var/cache shouldn't contain old caches at this point
timestamp_after_going_down = time.time()
total_time_down = timestamp_after_going_down - timestamp_before_going_down
print(colors.green('\n!! MAINTENANCE MODE DISABLED - WEBSHOP IS AVAILABLE AGAIN (downtime: %.2f seconds) !!\n' % total_time_down))
# cleanup older releases, tnx to http://stackoverflow.com/a/34862475/145829
with cd(env.releases_dir):
run('ls -1tp | grep "/$" | tail -n +4 | tr "\\n" "\\0" | xargs -0 --no-run-if-empty rm -R --')
notify(':tada: _%s_ finished deploying the *%s* branch to the *%s* environment at %s :thumbsup:' % (env.local_user, env.git_branch, env.name, env.domain))
except:
print(colors.red('\nSomething went wrong, please check above output to figure out what caused it!\n'))
notify(':bangbang: _%s_ *failed* to deploy the *%s* branch to the *%s* environment at %s :collision:' % (env.local_user, env.git_branch, env.name, env.domain))