Allow more customization for backup app deployment
This commit is contained in:
parent
2a6b25215f
commit
2fcb81e0ae
|
@ -29,7 +29,7 @@ Fabric deployment and maintenance.
|
|||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
from .core import put, upload_template, make_deploy, mkdir, rsync
|
||||
from .core import put, upload_template, make_deploy, mkdir, rsync, UNSPECIFIED
|
||||
from .core import make_system_user, set_timezone, agent_sudo
|
||||
from .core import get_debian_version, get_ubuntu_version
|
||||
|
||||
|
|
|
@ -31,13 +31,24 @@ import datetime
|
|||
from fabric.api import cd, sudo
|
||||
from fabric.contrib.files import exists
|
||||
|
||||
from rattail_fabric import make_deploy, mkdir, python
|
||||
from rattail_fabric import make_deploy, mkdir, python, UNSPECIFIED
|
||||
|
||||
|
||||
deploy_generic = make_deploy(__file__)
|
||||
|
||||
|
||||
def deploy_backup_app(deploy, envname, config=None, everything=None, crontab=None, user='rattail', runat=None):
|
||||
def deploy_backup_everything(**context):
|
||||
"""
|
||||
Deploy the generic `backup-everything` script
|
||||
"""
|
||||
context.setdefault('envname', 'backup')
|
||||
context.setdefault('user', 'rattail')
|
||||
deploy_generic('backup/backup-everything.mako', '/usr/local/bin/backup-everything', mode='0755',
|
||||
context=context)
|
||||
|
||||
|
||||
def deploy_backup_app(deploy, envname, mkvirtualenv=True, user='rattail',
|
||||
config=None, everything=None, crontab=None, runat=UNSPECIFIED):
|
||||
"""
|
||||
Make an app which can run backups for the server.
|
||||
"""
|
||||
|
@ -48,11 +59,12 @@ def deploy_backup_app(deploy, envname, config=None, everything=None, crontab=Non
|
|||
else:
|
||||
raise ValueError("Must provide config path for backup app")
|
||||
|
||||
if not runat:
|
||||
if runat is UNSPECIFIED:
|
||||
runat = datetime.time(0) # defaults to midnight
|
||||
|
||||
# virtualenv
|
||||
python.mkvirtualenv(envname, python='/usr/bin/python3', upgrade_setuptools=False)
|
||||
if mkvirtualenv:
|
||||
python.mkvirtualenv(envname, python='/usr/bin/python3', upgrade_setuptools=False)
|
||||
envpath = '/srv/envs/{}'.format(envname)
|
||||
sudo('chown -R {}: {}'.format(user, envpath))
|
||||
with cd(envpath):
|
||||
|
@ -76,20 +88,23 @@ def deploy_backup_app(deploy, envname, config=None, everything=None, crontab=Non
|
|||
sudo('bin/rattail -c app/rattail.conf make-config -T silent -O app/', user=user)
|
||||
|
||||
# backup-everything script
|
||||
everything_context = {'envname': envname}
|
||||
everything_context = {
|
||||
'envname': envname,
|
||||
'user': user,
|
||||
}
|
||||
if everything:
|
||||
deploy(everything, '/usr/local/bin/backup-everything', mode='0755', context=everything_context)
|
||||
else:
|
||||
deploy_generic('backup/backup-everything.mako', '/usr/local/bin/backup-everything', mode='0755',
|
||||
context=everything_context)
|
||||
deploy_backup_everything(**everything_context)
|
||||
|
||||
# crontab
|
||||
crontab_context = {
|
||||
'envname': envname,
|
||||
'pretty_time': runat.strftime('%I:%M %p'),
|
||||
'cron_time': runat.strftime('%M %H'),
|
||||
}
|
||||
if crontab:
|
||||
deploy(crontab, '/etc/cron.d/backup', context=crontab_context)
|
||||
else:
|
||||
deploy_generic('backup/crontab.mako', '/etc/cron.d/backup', context=crontab_context)
|
||||
if runat:
|
||||
crontab_context = {
|
||||
'envname': envname,
|
||||
'pretty_time': runat.strftime('%I:%M %p'),
|
||||
'cron_time': runat.strftime('%M %H'),
|
||||
}
|
||||
if crontab:
|
||||
deploy(crontab, '/etc/cron.d/backup', context=crontab_context)
|
||||
else:
|
||||
deploy_generic('backup/crontab.mako', '/etc/cron.d/backup', context=crontab_context)
|
||||
|
|
|
@ -38,6 +38,9 @@ from fabric.contrib.files import exists, append, upload_template as fab_upload_t
|
|||
from mako.template import Template
|
||||
|
||||
|
||||
UNSPECIFIED = object()
|
||||
|
||||
|
||||
def get_debian_version():
|
||||
"""
|
||||
Fetch the version of Debian running on the target system.
|
||||
|
|
|
@ -2,10 +2,12 @@
|
|||
|
||||
if [ "$1" = "-v" -o "$1" = "--verbose" ]; then
|
||||
VERBOSE='--verbose'
|
||||
QUIET=
|
||||
PROGRESS='--progress'
|
||||
CONFIG='app/rattail.conf'
|
||||
else
|
||||
VERBOSE=
|
||||
QUIET='--quiet'
|
||||
PROGRESS=
|
||||
CONFIG='app/silent.conf'
|
||||
fi
|
||||
|
@ -14,5 +16,15 @@ fi
|
|||
cd /srv/envs/${envname}
|
||||
|
||||
RATTAIL="bin/rattail --config=$CONFIG $PROGRESS"
|
||||
PIP='bin/pip'
|
||||
export PIP_CONFIG_FILE=pip.conf
|
||||
|
||||
$PIP install --upgrade pip
|
||||
|
||||
cd src/rattail
|
||||
sudo -u ${user} git pull $QUIET
|
||||
sudo -u ${user} find . -name '*.pyc' -delete
|
||||
cd -
|
||||
$PIP install --upgrade --upgrade-strategy eager --editable src/rattail
|
||||
|
||||
$RATTAIL backup
|
||||
|
|
Loading…
Reference in a new issue