diff --git a/roles/slurm_sql_bk/defaults/main.yml b/roles/slurm_sql_bk/defaults/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..efd656281b7008f562b3accfcb24d3838bbde76b --- /dev/null +++ b/roles/slurm_sql_bk/defaults/main.yml @@ -0,0 +1,6 @@ +--- +# 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" diff --git a/roles/slurm_sql_bk/files/id_rsa b/roles/slurm_sql_bk/files/id_rsa new file mode 100644 index 0000000000000000000000000000000000000000..6d48e8ae575dae346c40eddf015040c2368efa46 --- /dev/null +++ b/roles/slurm_sql_bk/files/id_rsa @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAp6+p7UzisLHTb7P4b2V3tvAtVDNuDV5gMiu+vyNPT/ihjgMo +BXgz5fuBMlv+1fsmiBAvZBzJD7m5+PkeQ2vXKGywGvUX6OHAppY6AtYf6T9b7gU6 +R1JgXTwu3HTNgtUZ87NvkxbS3jggL40Q6v+MJyXWfS76oBKp8lDVzS27wFDlrMYd +OdFKeV+KNV68rKziBhTIVQ2B5bq3OhDXISR1jOKHPPEeZVtX9Qmkm10n+0UstyQ6 +UpzOMabY4BiHJh6lrOrnsJ7nAB1sezz8tqLSKvD9Z9i9VlI2aBXgPmNEdqario7F +v5afAsGxVyngXnXqxtKU4e7xGSQ2JlEeYJBGgQIDAQABAoIBAQCLWgluQknVK0KZ +/scD1CADsF8LLV5Uz8xDhWUUNMTRob6oZOkaeoUup677acZCj1+7DTBFE0LnxaHO +TUCgKPt6BbDoBiyjhRBzoD5/YvDMBrJgAIopAUVB1iTfYlXzVyMlCkY7x2jf8WaV +/bZEhLA1TFWOXL88zaXb0N+MjmgL7hY3yP/i8+6dbDUkPsqnatLPYCNfqxzp+rOZ +XXCg8DQnfKu32ZyEiBfPqa/DOrL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k/files/id_rsa.pub new file mode 100644 index 0000000000000000000000000000000000000000..aa5bb0c5c4844274afb88d84da91c8ef4f3f800a --- /dev/null +++ b/roles/slurm_sql_bk/files/id_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCnr6ntTOKwsdNvs/hvZXe28C1UM24NXmAyK76/I09P+KGOAygFeDPl+4EyW/7V+yaIEC9kHMkPubn4+R5Da9cobLAa9Rfo4cCmljoC1h/pP1vuBTpHUmBdPC7cdM2C1Rnzs2+TFtLeOCAvjRDq/4wnJdZ9LvqgEqnyUNXNLbvAUOWsxh050Up5X4o1XrysrOIGFMhVDYHlurc6ENchJHWM4oc88R5lW1f1CaSbXSf7RSy3JDpSnM4xptjgGIcmHqWs6uewnucAHWx7PPy2otIq8P1n2L1WUjZoFeA+Y0R2pquKjsW/lp8CwbFXKeBederG0pTh7vEZJDYmUR5gkEaB root@m3-sql0 diff --git a/roles/slurm_sql_bk/tasks/main.yml b/roles/slurm_sql_bk/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..1bfd3276eaa3bf0ec48d495b97ee3b4968c4cd13 --- /dev/null +++ b/roles/slurm_sql_bk/tasks/main.yml @@ -0,0 +1,40 @@ +--- +# 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' diff --git a/roles/slurm_sql_bk/templates/backup_mysql_for_slurm.sh.j2 b/roles/slurm_sql_bk/templates/backup_mysql_for_slurm.sh.j2 new file mode 100644 index 0000000000000000000000000000000000000000..8b5c9cdcfb3a1629291d5c1fc1c20ed7c502a3a9 --- /dev/null +++ b/roles/slurm_sql_bk/templates/backup_mysql_for_slurm.sh.j2 @@ -0,0 +1,17 @@ +#!/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 diff --git a/roles/slurm_sql_bk/templates/delete_old_mysql_bk.sh.j2 b/roles/slurm_sql_bk/templates/delete_old_mysql_bk.sh.j2 new file mode 100644 index 0000000000000000000000000000000000000000..6f012295891ba37724ee3dc8076b2e6af451c4d9 --- /dev/null +++ b/roles/slurm_sql_bk/templates/delete_old_mysql_bk.sh.j2 @@ -0,0 +1,11 @@ +#!/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 {} \; + diff --git a/roles/slurm_sql_bk/templates/mysql.conf.j2 b/roles/slurm_sql_bk/templates/mysql.conf.j2 new file mode 100644 index 0000000000000000000000000000000000000000..ea91192ca855a9b218f9714654ca91f14e58ab84 --- /dev/null +++ b/roles/slurm_sql_bk/templates/mysql.conf.j2 @@ -0,0 +1,3 @@ +[client] +password="{{ sqlrootPasswd }}" +user=root