• centos7关机自动进行远程服务器备份


    centos7关机自动进行远程服务器备份

    编写关机及其重启后执行的脚本

    注:实验发现关机及其重启后执行的脚本的脚本中不能嵌套调用其它脚本。

    该脚本需要应该与服务程序中ExecStart项相对应。及该脚本名为/home/lhx/reboot.sh
    且需要安装expectyum install expect

    vim /home/lhx/reboot.sh

    #!/bin/bash
    passwd="123456" 
    echo "shutdown or reboot at `date +'%Y%m%d%H%M'`" >> /home/redflag/mock/reboot.log
    /usr/bin/expect <<-EOF
    spawn rsync -arv /home/redflag/mock/ root@192.168.30.200:/home/liuhuaxian/bak/mock
    expect "*password"
    send "123456
    "
    expect eof
    EOF 
    

    编写关机需要启动的服务,由该服务来启动上面的脚本。

    vi /usr/lib/systemd/system/rebootSrv.service

    [Unit]
    Description=close services before reboot and shutdown
    DefaultDependencies=no 
    Before=shutdown.target reboot.target halt.target
    
    [Service] 
    Type=oneshot 
    ExecStart=/home/lhx/reboot.sh  #your path and filename
    
    [Install]
    WantedBy=halt.target reboot.target shutdown.target
    

    启动服务

    然后执行

    [root@localhost lhx]# systemctl enable rebootSrv.service
    Created symlink from /etc/systemd/system/halt.target.wants/rebootSrv.service to /usr/lib/systemd/system/rebootSrv.service.
    Created symlink from /etc/systemd/system/reboot.target.wants/rebootSrv.service to /usr/lib/systemd/system/rebootSrv.service.
    Created symlink from /etc/systemd/system/shutdown.target.wants/rebootSrv.service to /usr/lib/systemd/system/rebootSrv.service.
    

    重启关机后就能自动执行/home/lhx/reboot.sh该脚本。

  • 相关阅读:
    男孩的眼泪
    清冷
    Java随笔
    Java随笔
    skip a transaction in goldengate(跳过一个事务OGG)
    Oracle性能问题一般排查方法
    Oracle GoldenGate(ogg)安装经验大汇总,采坑总结,绝对干货!
    ORACLE 11G 性能诊断优化之ASH实战分析详解
    Oracle SQL性能优化40条 | 收藏了!
    GoldenGate OGG ORACLE数据复制实施方案
  • 原文地址:https://www.cnblogs.com/DXGG-Bond/p/13356684.html
Copyright © 2020-2023  润新知