Commit 16ed9a45 authored by Xavier Perseguers's avatar Xavier Perseguers
Browse files

[FEATURE] Backup script for the Pootle database

Change-Id: I0e94fb1a0a4cd81dc15be3c54fd780008c920f0c
Reviewed-on: http://review.typo3.org/42012

Reviewed-by: Xavier Perseguers's avatarXavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers's avatarXavier Perseguers <xavier@typo3.org>
parent 1af6c4dd
#!/usr/bin/env bash
. /home/pootle/scripts/etc/pootle.conf
DATABASE_NAME=$(grep -A8 DATABASES ${POOTLE_CONF} | grep NAME | sed -r "s/^.*: '(.*)'.*$/\1/")
DATABASE_USER=$(grep -A8 DATABASES ${POOTLE_CONF} | grep USER | sed -r "s/^.*: '(.*)'.*$/\1/")
DATABASE_PASSWORD=$(grep -A8 DATABASES ${POOTLE_CONF} | grep PASSWORD | sed -r "s/^.*: '(.*)'.*$/\1/")
DATABASE_HOST=$(grep -A8 DATABASES ${POOTLE_CONF} | grep HOST | sed -r "s/^.*: '(.*)'.*$/\1/")
echo "[INFO] Pootle database: ${DATABASE_NAME}"
echo "[INFO] Pootle username: ${DATABASE_USER}"
echo "[INFO] Pootle DB host: ${DATABASE_HOST}"
MYSQL_CONNECT="--host=${DATABASE_HOST} -u ${DATABASE_USER} --password=${DATABASE_PASSWORD}"
NOW="$(date +"%Y-%m-%d")-$(date +"%H%M%S")"
DUMP_FILE="${DATABASE_NAME}_${NOW}.sql"
mkdir -p ${POOTLE_BACKUP_ROOT}
echo -n "[INFO] Dumping database structure ... "
mysqldump ${MYSQL_CONNECT} --no-data --databases ${DATABASE_NAME} \
> ${POOTLE_BACKUP_ROOT}/${DUMP_FILE}
echo "done."
echo -n "[INFO] Dumping database content (without cache data) ... "
mysqldump ${MYSQL_CONNECT} --hex-blob --databases ${DATABASE_NAME} \
--ignore-table=${DATABASE_NAME}.django_session \
--ignore-table=${DATABASE_NAME}.pootlecache \
>> ${POOTLE_BACKUP_ROOT}/${DUMP_FILE}
echo "done."
echo -n "[INFO] Compressing backup file ... "
gzip ${POOTLE_BACKUP_ROOT}/${DUMP_FILE}
echo "done."
echo "[INFO] Archive: ${POOTLE_BACKUP_ROOT}/${DUMP_FILE}.gz"
# Create link to latest dump
echo "[INFO] Updating link to latest dump"
pushd ${POOTLE_BACKUP_ROOT} >/dev/null
rm -f latest.sql.gz
ln -s ${DUMP_FILE}.gz latest.sql.gz
popd >/dev/null
echo "[INFO] Link: ${POOTLE_BACKUP_ROOT}/latest.sql.gz"
# Remove oldest dumps
echo "[INFO] Removing backup older than ${POOTLE_BACKUP_DAYS} days"
find ${POOTLE_BACKUP_ROOT} -type f -mtime +${POOTLE_BACKUP_DAYS} -delete
echo "[INFO] ====== BACKUP FINISHED ======"
# Cron jobs for Pootle and TYPO3
# TYPO3 system extensions
45 1 * * * pootle /home/pootle/scripts/bin/build-sysext-language-pack 2>&1 >/tmp/build-core.log
0 5 * * * pootle /home/pootle/scripts/bin/update-typo3-core-template 2>&1 >/tmp/update-core.log
# 3rd party extensions
15 2 * * * pootle /home/pootle/scripts/bin/build-language-pack 2>&1 >/tmp/build-all.log
0 4 * * * pootle /home/pootle/scripts/bin/update-all-extensions 2>&1 >/tmp/update-all-extensions.log
# Backup
0 3 * * * pootle /home/pootle/scripts/bin/backup-database >/dev/null 2>&1
......@@ -38,5 +38,8 @@
- name: Register Pootle server configuration
template: src=scripts/etc/pootle.conf.j2 dest=/home/pootle/scripts/etc/pootle.conf owner=pootle group=pootle
- name: Register update and packaging cron jobs
copy: src=typo3.cron dest=/etc/cron.d/typo3
- name: Create directory for Git clones ({{ pootle_git_directory }})
file: path={{ pootle_git_directory }} state=directory owner=pootle group=pootle
\ No newline at end of file
......@@ -2,6 +2,9 @@ POOTLE_BIN={{ pootle_virtualenv }}/bin/pootle
POOTLE_CONF=/etc/pootle/pootle.conf
POOTLE_SCRIPT_HOME=/home/pootle/scripts
POOTLE_BACKUP_ROOT=/home/pootle/backup
POOTLE_BACKUP_DAYS=28
POOTLE_MANAGE=${POOTLE_SCRIPT_HOME}/bin/pootle-manage
T3XUTILS=${POOTLE_SCRIPT_HOME}/bin/t3xutils.phar
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment