定义timer文件
进入目录/usr/lib/systemd/system,按如下文件建立timer:
[Unit] Description=Runs db backup every hour [Timer] # Time to wait after booting before we run first time OnBootSec=10min # Time between running each consecutive time OnUnitActiveSec=1h Unit=db_backup.service [Install] WantedBy=multi-user.target
定义service文件
进入目录/usr/lib/systemd/system,按如下文件建立service:
[Unit] Description=Backup database [Service] Type=simple ExecStart=/usr/local/bin/db_backup
写数据库备份脚本
创建文件/usr/local/bin/db_backup,并写入数据库备份语句,例如:
#!/usr/bin/bash /usr/bin/mysqldump -umy_username -pmy_password -h192.168.1.xx --databases my_database > /path/to/backup/dir/my_database.`date +'%Y%m%d%H%'`.sql
启用并运行timer
命令行下运行如下命令:
systemctl enable db_backup.timer systemctl start db_backup.timer
计划任务执行后,即会在数据库备份的目录生成数据库备份文件
原文地址:http://joelhy.github.io/2015/06/18/backup-database-using-systemd-timer/
本文地址: https://www.linuxprobe.com/systemd-timer-mysql.html 编辑:岳国帅,审核员:逄增宝
本文原创地址:https://www.linuxprobe.com/systemd-timer-mysql.html编辑:public,审核员:暂无
我的微信
这是我的微信扫一扫
评论