Skip to content
Snippets Groups Projects
Commit 88788c8c authored by Simon Michnowicz's avatar Simon Michnowicz
Browse files

Changes to copy mysql dump to remote machine. This involves a new archicture...

Changes to copy mysql dump to remote machine. This involves a new archicture and the ability to regenerate ssh keys
parent 55aa52b7
No related branches found
No related tags found
1 merge request!229Sql backup
--- ---
# this code is for the sql server only #
- name: template sql backupscript to /etc/cron.daily #first generate ssh keys Gif the variable "create_key" is defined.
template: src="backup_mysql_for_slurm.sh.j2" dest="/etc/cron.daily/backup_mysql_for_slurm.sh" mode="700" #
sudo: true - name: delete any existing local private key
when: server == 'True' local_action: command rm -f ./slm_db_backup
- name: Create directory {{ SQL_BK_DIR }} when: create_key is defined and create_key=="True"
file: path={{ SQL_BK_DIR }} state=directory - name: delete any existing local public keys
sudo: true local_action: command rm -f ./slm_db_backup.pub
when: server == 'True' when: create_key is defined and create_key=="True"
- name: generate ssh keys if necessary
#this command will create a two files "slm_db_backup" and "slm_db_backup.pub"
local_action: command ssh-keygen -t rsa -f slm_db_backup -P ""
when: create_key is defined and create_key=="True"
- name: copy private key to management node
copy:
src: "./slm_db_backup"
dest: "/root/.ssh"
owner: root
group: root
mode: '600'
become: True
become_user: root
when: create_key is defined and create_key=="True"
- name: copy public key to authorised key file of backup volume machine
local_action: command ssh-copy-id -i ./slm_db_backup.pub {{ SQL_BK_DEST_HOST }}
when: create_key is defined and create_key=="True"
#
# now setup cronjob on management node
#
- name: ensure {{ MGMT_BIN_DIR }} exists
file:
path: "{{ MGMT_BIN_DIR }}"
state: directory
become: true
become_user: root
- name: "template sql backupscript to {{ MGMT_BIN_DIR }}"
template: src="backup_mysql_for_slurm.sh.j2" dest="{{ MGMT_BIN_DIR }}/backup_mysql_for_slurm.sh" mode="700"
become: true
become_user: root
- name: Make a daily crontab entry
cron:
name: "Backup of MySQL Database for Slurm"
job: "{{ MGMT_BIN_DIR }}/backup_mysql_for_slurm.sh"
hour: 23
minute: 55
become: true
become_user: root
- name: Create directory {{ SQL_BK_DATA_DIR }}
file: path={{ SQL_BK_DATA_DIR }} state=directory
become: true
become_user: root
- name: template mysql config file to server - name: template mysql config file to server
template: src="mysql.conf.j2" dest="{{ SQL_BK_DIR }}/mysql.conf" mode="600" template: src="mysql.conf.j2" dest="{{ MGMT_BIN_DIR }}/mysql.conf" mode="600"
sudo: true become: true
when: server == 'True' become_user: root
- name: copy ssh pub key to .ssh if it does not exist already #
copy: src="id_rsa.pub" dest="/root/.ssh/id_rsa.pub" # template delete file to localhost.then copy to remote host
sudo: true #
when: server == 'True' - name: delete local del file
- name: copy ssh private key to .ssh if it does not exist already local_action: command rm -f ./delete_old_mysql_bk.sh
copy: src="id_rsa" dest="/root/.ssh/id_rsa" mode="600" - name: template delete script to local dir
sudo: true local_action: template src=delete_old_mysql_bk.sh.j2 dest=./delete_old_mysql_bk.sh
when: server == 'True' - name: copy backup script to server ec2-user@{{ SQL_BK_DEST_HOST }}
local_action: command scp -i ./slm_db_backup ./delete_old_mysql_bk.sh "ec2-user@{{ SQL_BK_DEST_HOST }}:"
#this code is for the Destination Node only - name: insert delete cron job entry on remote server
- name: create dummy user account local_action: command ssh ec2-user@{{ SQL_BK_DEST_HOST }} "{ crontab -l ; echo '#delete old slurm backups' ; echo '00 23 * * * /home/ec2-user/backup_mysql_for_slurm.sh' ; } | crontab - "
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'
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