| #!/bin/bash |
| # |
| # A cron job may call this with a line such as: |
| # 53 14 * * * sh /home/cldrbackup/backup.sh >/dev/null 2>&1 |
| # It may be configured by an ansible script such as backup-db-playbook.yml |
| # |
| # The backups might be made faster by saving the sql file in a fast |
| # temporary directory (mktemp? /mnt?) -- let's test that at a time |
| # when Survey Tool is closed and daily backups aren't essential |
| |
| DATABASE_NAME={{ cldr_database_name }} |
| FNAME={{ cldr_database_name }}-DUMP-`date +%Y-%m-%d` |
| RSYNC_DEST={{ cldr_db_backup_destination }} |
| |
| cd /home/cldrbackup |
| mysqldump ${DATABASE_NAME} --add-drop-table --create-options --default-character-set=utf8mb4 > ${FNAME}.sql |
| |
| # Wait until mysqldump is finished before running xz, to minimize db disruption (don't use | pipe) |
| xz ${FNAME}.sql |
| rsync --quiet --remove-source-files ${FNAME}.sql.xz ${RSYNC_DEST} |