Skip to content
Snippets Groups Projects
Commit b4c0642b authored by Chris Hines's avatar Chris Hines
Browse files

Merge branch 'sqlbackup' into 'master'

Added new role to enable Slurm DB SQL to be backed up and then ssh to a node.

See merge request !125
parents d085776b 63ee9bab
No related branches found
No related tags found
1 merge request!125Added new role to enable Slurm DB SQL to be backed up and then ssh to a node.
---
# for slurm mysql backup
SQL_BK_DIR: "/mnt/db_backup"
SQL_BK_DEST_HOST: "m3-mgmt1"
SQL_BK_DEST_DIR: "/mnt/home/slurm_db_backup"
SQL_USER: "slurmsqlbk"
---
# this code is for the sql server only
- name: template sql backupscript to /etc/cron.daily
template: src="backup_mysql_for_slurm.sh.j2" dest="/etc/cron.daily/backup_mysql_for_slurm.sh" mode="700"
sudo: true
when: server == 'True'
- name: Create directory {{ SQL_BK_DIR }}
file: path={{ SQL_BK_DIR }} state=directory
sudo: true
when: server == 'True'
- name: template mysql config file to server
template: src="mysql.conf.j2" dest="{{ SQL_BK_DIR }}/mysql.conf" mode="600"
sudo: true
when: server == 'True'
- name: copy ssh pub key to .ssh if it does not exist already
copy: src="id_rsa.pub" dest="/root/.ssh/id_rsa.pub"
sudo: true
when: server == 'True'
- name: copy ssh private key to .ssh if it does not exist already
copy: src="id_rsa" dest="/root/.ssh/id_rsa" mode="600"
sudo: true
when: server == 'True'
#this code is for the Destination Node only
- name: create dummy user account
user: name="{{ SQL_USER }}" comment="Account for scp of slurm sql backups"
sudo: true
when: server == 'False'
- name: Add MySQL server ssh key to authorised_files on management nodes"
authorized_key: user="{{ SQL_USER }}" state=present key="{{ lookup('file', 'id_rsa.pub') }}" #"
sudo: true
when: server == 'False'
- name: ensure the dest directory exists (for backups to be copied too)
file: path={{ SQL_BK_DEST_DIR }} state=directory owner={{ SQL_USER }}
sudo: true
when: server == 'False'
- name: setup cron job to delete old slurm logs
template: src="delete_old_mysql_bk.sh.j2" dest="/etc/cron.daily/delete_old_mysql_bk.sh" mode="700"
sudo: true
when: server == 'False'
#!/bin/sh
#
# mysql dump for slurm.
# S.Michnowicz
# 20/Jan/2016
#
TIME=$(date '+%y-%m-%d')
DIR={{ SQL_BK_DIR }}
NAME="$DIR/mysql_dump_20${TIME}.sql"
sudo mysqldump --defaults-file=$DIR/mysql.conf slurm_acct_db > $NAME
sudo chmod go-r $NAME
sudo gzip -f $NAME
#scp file to dummy user @ Destination Node and Directory
scp ${NAME}.gz {{ SQL_USER }}@{{ SQL_BK_DEST_HOST }}:{{ SQL_BK_DEST_DIR }}
rm -f ${NAME}.gz
#!/bin/sh
#
# delete old backups from slurm mysql
# S.Michnowicz
#
# 2 day timeframe specified by -mtime +2
# also includes email check
#find {{ SQL_BK_DEST_DIR }} -type f -mtime +2 -name 'mysql_dump_*.gz' -execdir mail -s "Deleting {}" simon.michnowicz@monash.edu < /dev/null \; -execdir rm -f {} \;
find {{ SQL_BK_DEST_DIR }} -type f -mtime +7 -name 'mysql_dump_*.gz' -execdir rm -f {} \;
[client]
password="{{ sqlrootPasswd }}"
user=root
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment