[svc]ansible 백업 구현 메일 원격 압축 해제

3678 단어
후속 회의는 간단명료함에서 복잡함, 문법부터 응용 사례, 대로에서 간략함까지의 원칙에 따라 ansible를 추진한다.
1. 원격 압축 해제.원격 압축 패키지를 원격 디렉터리로 압축 풀기
- hosts: nodexx
  remote_user: root
  vars:
  - dfpath: "/backup/scm-data/"
  tasks:
    - name "this vm restore scm data to test data on app"
      unarchive:
        src: /tmp/etc.tar.gz  #   url,     
        dest: /root
        remote_src: "{{ dfpath }}"

2, 원격 압축 및 복구
4
- hosts: nodexx
    remote_user: root
    vars:
      - sfpath: "/backup/scm-data/*_$(date +%F)_scmdata.tar.gz"
      - dfpath: "/backup/scm-data/"
    - name: Package | make /root/.scm to tar.gz package on node14
      raw: cd /root && tar zcf /data/backup/scm-data/`ifconfig|sed -n '2p'|awk -F':' '{print $2}'|awk '{print $1}'`_$(date +%F)_scmdata.tar.gz .scm


    - name: Download | copy nodexx's tar.gz to ansible vm([this vm] /data/scm-data)
      synchronize:
        src: "{{ sfpath }}"
        dest: "{{ dfpath }}"
        mode: pull
# 이 실행 명령과 cd/& echo 1>1.txt, 셸이 작동하지 않습니다.raw 모듈을 사용해야 합니다
#변수 정의
3, 이메일 모듈로 이메일 보내기
- hosts: nodexx
    remote_user: root
    - name: sendMail to op
      mail:
        host: smtp.sina.com
        port: 25
        username: [email protected]
        password: xxx
        from: [email protected] (lannymxl)
        to: Jack 
        # cc: John Doe , Suzie Something 
        # cc: Wang Wu , Li Si 
        attach: /etc/fstab /etc/hosts
        subject: Backup-scm successfully
        body: 'System {{ ansible_hostname }}-192.168.x.x from 192.168.x.x scm-backup has been successfully provisioned.'

4, scm 호스트에서 매일 백업, 백업 완료 후 메일 보내기--ansible 구현
- hosts: nodexx-scm
  remote_user: root
  vars:
  - sfpath: "/backup/scm-data/*_$(date +%F)_scmdata.tar.gz"
  - dfpath: "/backup/scm-data/"
  tasks:#        ,       scm-data.tar.gz  2,           
    - name: Clean | keeping [scm-server-node14]'s /backup/scm-data dir only have one tar pkg
      shell: find /backup/scm-data/ -name "*.tar.gz"  -type f -mtime|xargs rm -f


    - name: Package | make /root/.scm to tar.gz package on node14
      raw: cd /root && tar zcf /data/backup/scm-data/`ifconfig|sed -n '2p'|awk -F':' '{print $2}'|awk '{print $1}'`_$(date +%F)_scmdata.tar.gz .scm


    - name: Download | copy node14's tar.gz to ansible vm([this vm] /data/scm-data)
      synchronize:
        src: "{{ sfpath }}"
        dest: "{{ dfpath }}"
        mode: pull
    
    #     
    # - name "this vm restore scm data to test data on app"
    #   unarchive:
    #     src: "{{ dfpath }}"
    #     dest: /root
    #     remote_src: True
- hosts: localhost
  remote_user: root
  tasks: 
  #    scm   ,   7     .    ,   .
    - name: Keeps scm-data.tar.gz of 7 days in local
      shell: find /backup/scm-data/ -name "*.tar.gz"  -type f -mtime|xargs rm -f


    - name: sendMail to op
      mail:
        host: smtp.sina.com
        port: 25
        username: [email protected]
        password: xxx
        from: [email protected] (lannymxl)
        to: Jack 
        # cc: John Doe , Suzie Something 
        # cc: Wang Wu , Li Si 
        attach: /etc/fstab /etc/hosts
        subject: Backup-scm successfully
        body: 'System {{ ansible_hostname }}-192.168.x.x from 192.168.x.x scm-backup has been successfully provisioned.'

좋은 웹페이지 즐겨찾기