{"id":16045,"date":"2023-07-29T05:55:12","date_gmt":"2023-07-28T21:55:12","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=16045"},"modified":"2023-07-29T05:55:12","modified_gmt":"2023-07-28T21:55:12","slug":"systemd-timer-mysql","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/systemd-timer-mysql.html","title":{"rendered":"\u4f7f\u7528 systemd timer \u5907\u4efd\u6570\u636e\u5e93"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4e3b\u8981\u7684Linux\u53d1\u884c\u7248\u90fd\u6539\u7528systemd \u6765\u66ff\u4ee3 System V\u542f\u52a8\u65b9\u5f0f\uff0c\u5176\u4e2d systemd timer \u80fd\u66ff\u4ee3 crontab \u8ba1\u5212\u4efb\u52a1\u7684\u5927\u90e8\u5206\u529f\u80fd\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u7528systemd timer\u5982\u4f55\u5b9e\u73b0\u6570\u636e\u5e93\u5907\u4efd\uff0c\u5176\u4ed6\u7c7b\u578b\u7684\u8ba1\u5212\u4efb\u52a1\u53ef\u4ee5\u540c\u7406\u5b9e\u73b0\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"SystemD\"<\/p>\n

\u5b9a\u4e49timer\u6587\u4ef6<\/strong><\/div>\n

\u8fdb\u5165\u76ee\u5f55\/usr\/lib\/systemd\/system\uff0c\u6309\u5982\u4e0b\u6587\u4ef6\u5efa\u7acbtimer\uff1a<\/p>\n

[Unit]\r\nDescription=Runs db backup every hour\r\n\r\n[Timer]\r\n# Time to wait after booting before we run first time\r\nOnBootSec=10min\r\n# Time between running each consecutive time\r\nOnUnitActiveSec=1h\r\nUnit=db_backup.service\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n
\u5b9a\u4e49service\u6587\u4ef6<\/strong><\/div>\n

\u8fdb\u5165\u76ee\u5f55\/usr\/lib\/systemd\/system\uff0c\u6309\u5982\u4e0b\u6587\u4ef6\u5efa\u7acbservice\uff1a<\/p>\n

[Unit]\r\nDescription=Backup database\r\n\r\n[Service]\r\nType=simple\r\nExecStart=\/usr\/local\/bin\/db_backup\r\n<\/pre>\n
\u5199\u6570\u636e\u5e93\u5907\u4efd\u811a\u672c<\/strong><\/div>\n

\u521b\u5efa\u6587\u4ef6\/usr\/local\/bin\/db_backup\uff0c\u5e76\u5199\u5165\u6570\u636e\u5e93\u5907\u4efd\u8bed\u53e5\uff0c\u4f8b\u5982\uff1a<\/p>\n

#!\/usr\/bin\/bash\r\n\/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\r\n<\/pre>\n
\u542f\u7528\u5e76\u8fd0\u884ctimer<\/strong><\/div>\n

\u547d\u4ee4\u884c\u4e0b\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

systemctl enable db_backup.timer\r\nsystemctl start db_backup.timer\r\n<\/pre>\n

\u8ba1\u5212\u4efb\u52a1\u6267\u884c\u540e\uff0c\u5373\u4f1a\u5728\u6570\u636e\u5e93\u5907\u4efd\u7684\u76ee\u5f55\u751f\u6210\u6570\u636e\u5e93\u5907\u4efd\u6587\u4ef6<\/p>\n

\n

\u539f\u6587\u5730\u5740\uff1ahttp:\/\/joelhy.github.io\/2015\/06\/18\/backup-database-using-systemd-timer\/<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1a http:\/\/lrxjmw.cn\/systemd-timer-mysql.html \u200e<\/a>\u7f16\u8f91\uff1a\u5cb3\u56fd\u5e05\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb \u4e3b\u8981\u7684Linux\u53d1\u884c\u7248\u90fd\u6539\u7528systemd \u6765\u66ff\u4ee3 System V\u542f\u52a8\u65b9\u5f0f\uff0c\u5176\u4e2d systemd ti […]<\/p>\n","protected":false},"author":63,"featured_media":16052,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-16045","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=16045"}],"version-history":[{"count":12,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16045\/revisions"}],"predecessor-version":[{"id":278993,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/16045\/revisions\/278993"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/16052"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=16045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=16045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=16045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}