mysqldump dbname | gzip -9c > ~/dbname.`date +%Y-%m-%d.%H%M`.sql.gz ; ls -la ~/ | grep `date +%Y-%m-%d`
- hosts: dbserver remote_user: jlouthan tasks: - name: Backup Prod Database shell: mysqldump dbdump | gzip -9c > ~jlouthan/dbdump.`date +%Y-%m-%d`.sql.gz become: yes become_method: sudo
- name: Check to see if the dbdump has been successfully created
wait_for: path=~jlouthan/dbdump.`date +%Y-%m-%d`.sql.gz
- hosts: dbserver remote_user: jlouthan tasks: - name: Get current timestamp local_action: command bash -c "date +%Y-%m-%d.%H%M" register: timestamp run_once: true
- debug: var=timestamp.stdout
- name: Get current datestamp local_action: command bash -c "date +%Y-%m-%d" register: datestamp run_once: true
- debug: var=datestamp.stdout
- name: Backup Stag Database mysql_db: state=dump name=dbname target=~jlouthan/dbname.{{ datestamp }}.sql become: yes become_method: sudo - name: See the the Stag DB backup shell: ls -la ~jlouthan/ | grep {{ timestamp }} register: dumpstag - debug: var=dumpstag.stdout_lines
- name: Make sure that the Stag DB Backups look good before you continue pause:[jlouthan@ansible-server Playbooks]$ ansible-playbook test-backup-Client-staging-db.ymlSUDO password:
PLAY [dbserver] **************************************************************
GATHERING FACTS ***************************************************************
ok: [dbserver]
TASK: [Get current timestamp] *************************************************changed: [dbserver -> 127.0.0.1]
TASK: [debug var=timestamp.stdout] ********************************************ok: [dbserver] => { "var": { "timestamp.stdout": "2016-04-22.1507" }}
TASK: [Get current datestamp] *************************************************changed: [dbserver -> 127.0.0.1]
TASK: [debug var=datestamp.stdout] ********************************************ok: [dbserver] => { "var": { "datestamp.stdout": "2016-04-22" }}
TASK: [Backup Stag Database] **************************************************failed: [dbserver] => {"failed": true}msg: this module requires key=value arguments (['state=dump', 'name=dbname', 'target=~jlouthan/dbname.{changed:', 'True,', 'end:', '2016-04-22 15:07:30.816204,', 'stdout:', '2016-04-22,', 'cmd:', '[bash,', '-c,', 'date +%Y-%m-%d],', 'rc:', '0,', 'start:', '2016-04-22 15:07:30.810278,', 'stderr:', ',', 'delta:', '0:00:00.005926,', 'invocation:', '{module_name:', 'ucommand,', 'module_complex_args:', '{},', 'module_args:', 'ubash -c "date +%Y-%m-%d"},', 'stdout_lines:', '[2016-04-22],', 'warnings:', '[]}.sql'])
FATAL: all hosts have already failed -- aborting
PLAY RECAP ******************************************************************** to retry, use: --limit @/home/jlouthan/test-backup-Client-staging-db.retry
dbserver : ok=5 changed=2 unreachable=0 failed=1---- hosts: dbserver remote_user: jlouthan tasks: - name: Get current timestamp local_action: command bash -c 'date +%Y-%m-%d.%H%M' # Consider switch this to a shell module with date command register: timestamp run_once: true
- debug: var=timestamp.stdout
- name: Get current datestamp local_action: command bash -c 'date +%Y-%m-%d' # Consider switch this to a shell module with date command register: datestamp run_once: true
- debug: var=datestamp.stdout
- name: Backup dbname Database mysql_db: "state=dump name=dbname target=~jlouthan/dbname.{{ timestamp.stdout }}.sql" become: yes become_method: sudo
- name: See the DB Backups shell: ls -la ~jlouthan/ | grep {{ datestamp.stdout }} register: dumpdb
- debug: var=dumpdb.stdout_lines
- name: Make sure that the dbname DB Backups look good before you continue pause:--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b3befc8a-0ea3-4f17-bc63-dfc04f7d1ac8%40googlegroups.com.