進入目錄/usr/lib/systemd/system,按如下文件建立timer:
[Unit]Description=Runs db backup every hour[Timer]# Time to wait after booting before we run first timeOnBootSec=10min# Time between running each consecutive timeOnUnitActiveSec=1hUnit=db_backup.service[Install]WantedBy=multi-user.target定義service文件
進入目錄/usr/lib/systemd/system,按如下文件建立service:
[Unit]Description=Backup database[Service]Type=simpleExecStart=/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.timersystemctl start db_backup.timer
計劃任務執行後,即會在數據庫備份的目錄生成數據庫備份文件
原文地址:http://joelhy.github.io/2015/06/18/backup-database-using-systemd-timer/
本文地址:http://www.linuxprobe.com/systemd-timer-mysql.html
進入目錄/usr/lib/systemd/system,按如下文件建立timer:
[Unit]Description=Runs db backup every hour[Timer]# Time to wait after booting before we run first timeOnBootSec=10min# Time between running each consecutive timeOnUnitActiveSec=1hUnit=db_backup.service[Install]WantedBy=multi-user.target定義service文件
進入目錄/usr/lib/systemd/system,按如下文件建立service:
[Unit]Description=Backup database[Service]Type=simpleExecStart=/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.timersystemctl start db_backup.timer
計劃任務執行後,即會在數據庫備份的目錄生成數據庫備份文件
原文地址:http://joelhy.github.io/2015/06/18/backup-database-using-systemd-timer/
轉載地址:http://www.linuxprobe.com/systemd-timer-mysql.html
http://xxxxxx/Linuxjc/1137411.html TechArticle