Add upgrade, restart-overnight-backups scripts for generic backup app

This commit is contained in:
Lance Edgar 2019-09-30 15:37:21 -05:00
parent 067c02e965
commit 0b5f6234ad
4 changed files with 46 additions and 17 deletions

View file

@ -104,7 +104,7 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
# config
c.sudo("bash -l -c 'workon {} && cdvirtualenv && rattail make-appdir'".format(envname), user=user)
# note, config is owned by root regardless of `user` - since we always run backups as root
deploy(c, config, os.path.join(envpath, 'app/rattail.conf'), owner='root', mode='0600', use_sudo=True, context=context)
deploy(c, config, os.path.join(envpath, 'app/rattail.conf'), owner='root:{}'.format(user), mode='0640', use_sudo=True, context=context)
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T quiet -O app/'".format(envname), user=user)
c.sudo("bash -l -c 'workon {} && cdvirtualenv && bin/rattail -c app/rattail.conf make-config -T silent -O app/'".format(envname), user=user)
@ -156,6 +156,9 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
deploy_generic(c, 'backup/luigi-logging.conf.mako', '{}/app/luigi/luigi-logging.conf'.format(envpath),
owner=user, use_sudo=True, context={'envpath': envpath})
# needed for restarting luigi tasks
apt.install(c, 'at')
# app/luigitasks/overnight.py - should define the OvernightBackups wrapper task
path = '{}/luigi-overnight.py'.format(envname)
if deploy.local_exists(path):
@ -169,6 +172,10 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
deploy_generic(c, 'backup/overnight-backups.sh.mako', '{}/app/overnight-backups.sh'.format(envpath),
owner=user, mode='0755', use_sudo=True, context={'envpath': envpath})
# app/restart-overnight-backups.sh - generic script to restart OvernightBackups task
deploy_generic(c, 'backup/restart-overnight-backups.sh.mako', '{}/app/restart-overnight-backups.sh'.format(envpath),
owner=user, mode='0755', use_sudo=True, context={'envpath': envpath})
# supervisor / luigid
apt.install(c, 'supervisor')
deploy_generic(c, 'backup/supervisor.conf.mako', '/etc/supervisor/conf.d/backup.conf',
@ -178,6 +185,11 @@ def deploy_backup_app(c, deploy, envname, mkvirtualenv=True, user='rattail',
c.sudo('supervisorctl update')
c.sudo('supervisorctl start backup:')
# upgrade script
if install_rattail:
deploy_generic(c, 'backup/upgrade.sh.mako', '{}/app/upgrade.sh'.format(envpath),
owner=user, mode='0755', use_sudo=True, context={'envpath': envpath, 'user': user})
# backup-everything script
if install_rattail or everything:
everything_context = dict(context)

View file

@ -2,19 +2,16 @@
if [ "$1" = "-v" -o "$1" = "--verbose" ]; then
VERBOSE='--verbose'
QUIET=
PROGRESS='--progress'
CONFIG='/srv/envs/${envname}/app/rattail.conf'
else
VERBOSE=
QUIET='--quiet'
PROGRESS=
CONFIG='/srv/envs/${envname}/app/silent.conf'
fi
RATTAIL="/srv/envs/${envname}/bin/rattail --config=$CONFIG $PROGRESS $VERBOSE"
PIP="sudo -H -u ${user} PIP_CONFIG_FILE=/srv/envs/${envname}/pip.conf /srv/envs/${envname}/bin/pip"
# sanity check
if [ "$HOME" != '/root' ]; then
@ -25,18 +22,8 @@ if [ "$HOME" != '/root' ]; then
exit 1
fi
# upgrade pip
$PIP install $QUIET --upgrade pip
# upgrade rattail
cd /srv/envs/${envname}/src/rattail
if [ "$(sudo -H -u ${user} git status --porcelain)" != '' ]; then
sudo -H -u ${user} git status
exit 1
fi
sudo -H -u ${user} git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --upgrade --upgrade-strategy eager --editable .
# upgrade app
/srv/envs/${envname}/app/upgrade.sh $VERBOSE
# run backup
cd /srv/envs/${envname}

View file

@ -0,0 +1,5 @@
#!/bin/sh -e
DATE=`date --date='yesterday' +%Y-%m-%d`
echo "${envpath}/bin/rattail -c ${envpath}/app/silent.conf --no-versioning run-n-mail -S 'Backups (continued)' '${envpath}/app/overnight-backups.sh $DATE'" | at 'now + 1 minute'

View file

@ -0,0 +1,25 @@
#!/bin/sh -e
if [ "$1" = "-v" -o "$1" = "--verbose" ]; then
VERBOSE='--verbose'
QUIET=
else
VERBOSE=
QUIET='--quiet'
fi
PIP="sudo -H -u ${user} PIP_CONFIG_FILE=${envpath}/pip.conf ${envpath}/bin/pip"
# upgrade pip
$PIP install $QUIET --upgrade pip
# upgrade rattail
cd ${envpath}/src/rattail
if [ "$(sudo -H -u ${user} git status --porcelain)" != '' ]; then
sudo -H -u ${user} git status
exit 1
fi
sudo -H -u ${user} git pull $QUIET
find . -name '*.pyc' -delete
$PIP install $QUIET --upgrade --upgrade-strategy eager --editable .