歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> 使用 systemd timer 備份數據庫

使用 systemd timer 備份數據庫

日期:2017/3/6 9:35:26   编辑:學習Linux

使用 systemd timer 備份數據庫


使用 systemd timer 備份數據庫



使用 systemd timer 備份數據庫

導讀主要的Linux發行版都改用systemd 來替代 System V啟動方式,其中 systemd timer 能替代 crontab 計劃任務的大部分功能。本文介紹了用systemd timer如何實現數據庫備份,其他類型的計劃任務可以同理實現。

SystemD

定義timer文件

進入目錄/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 ‎


導讀主要的Linux發行版都改用systemd 來替代 System V啟動方式,其中 systemd timer 能替代 crontab 計劃任務的大部分功能。本文介紹了用systemd timer如何實現數據庫備份,其他類型的計劃任務可以同理實現。

SystemD

定義timer文件

進入目錄/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

Copyright © Linux教程網 All Rights Reserved