[FEATURE] Backup script for the Pootle database 12/42012/2
authorXavier Perseguers <xavier@typo3.org>
Tue, 28 Jul 2015 06:27:29 +0000 (08:27 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 28 Jul 2015 06:44:11 +0000 (08:44 +0200)
Change-Id: I0e94fb1a0a4cd81dc15be3c54fd780008c920f0c
Reviewed-on: http://review.typo3.org/42012
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
typo3/files/scripts/bin/backup-database [new file with mode: 0644]
typo3/files/typo3.cron [new file with mode: 0644]
typo3/tasks/main.yml
typo3/templates/scripts/etc/pootle.conf.j2

diff --git a/typo3/files/scripts/bin/backup-database b/typo3/files/scripts/bin/backup-database
new file mode 100644 (file)
index 0000000..a7d9fb0
--- /dev/null
@@ -0,0 +1,49 @@
+#!/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 ======"
diff --git a/typo3/files/typo3.cron b/typo3/files/typo3.cron
new file mode 100644 (file)
index 0000000..e298ca3
--- /dev/null
@@ -0,0 +1,12 @@
+# 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
index 272a3af..e30f94a 100644 (file)
@@ -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
index ed9b0ff..7d3d577 100644 (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