{"id":6174,"date":"2025-09-05T22:52:51","date_gmt":"2025-09-05T14:52:51","guid":{"rendered":"http:\/\/192.168.1.29\/?p=6174"},"modified":"2025-09-05T22:52:52","modified_gmt":"2025-09-05T14:52:52","slug":"%e8%87%aa%e5%8a%a8%e5%ae%9a%e6%97%b6%e5%a4%87%e4%bb%bd%e7%9b%ae%e5%bd%95%e7%9a%84python%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"http:\/\/xc.ipyingshe.net:5347\/?p=6174","title":{"rendered":"\u81ea\u52a8\u5b9a\u65f6\u5907\u4efd\u76ee\u5f55\u7684Python\u811a\u672c"},"content":{"rendered":"\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5b9a\u65f6\u5907\u4efd\u6307\u5b9a\u76ee\u5f55\u7684Python\u811a\u672c\u3002\u5b83\u4f1a\u5c06\u6e90\u76ee\u5f55\u590d\u5236\u5230\u76ee\u6807\u76ee\u5f55\uff0c\u5e76\u5728\u5907\u4efd\u6587\u4ef6\u5939\u540d\u79f0\u4e2d\u6dfb\u52a0\u65f6\u95f4\u6233\u4ee5\u4fbf\u533a\u5206\u4e0d\u540c\u5907\u4efd\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#backup_script.py Apply<br><code>import shutil<br>import os<br>import time<br>from datetime import datetime<br><br>def backup_directory(source, destination):<br>    # \u521b\u5efa\u5e26\u65f6\u95f4\u6233\u7684\u5907\u4efd\u76ee\u5f55\u540d<br>    timestamp = datetime.now().strftime(\"%Y%m%d_%H%M%S\")<br>    backup_dir = os.path.join(destination, f\"wordpress_backup_{timestamp}\")<br>    <br>    try:<br>        # \u590d\u5236\u6574\u4e2a\u76ee\u5f55\u6811<br>        shutil.copytree(source, backup_dir)<br>        print(f\"\u5907\u4efd\u6210\u529f\uff01\u5907\u4efd\u76ee\u5f55: {backup_dir}\")<br>        return True<br>    except Exception as e:<br>        print(f\"\u5907\u4efd\u5931\u8d25: {e}\")<br>        return False<br><br>def scheduled_backup(source, destination, interval_seconds):<br>    print(f\"\u5f00\u59cb\u5b9a\u65f6\u5907\u4efd\uff0c\u6e90\u76ee\u5f55: {source}, \u76ee\u6807\u76ee\u5f55: {destination}, \u5907\u4efd\u95f4\u9694: {interval_seconds}\u79d2\")<br>    <br>    while True:<br>        backup_directory(source, destination)<br>        # \u7b49\u5f85\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694<br>        time.sleep(interval_seconds)<br><br>if __name__ == \"__main__\":<br>    # \u5b9a\u4e49\u6e90\u76ee\u5f55\u548c\u76ee\u6807\u76ee\u5f55<br>    source_dir = r\"C:\\www\\WWW\\wordpress\"<br>    dest_dir = r\"D:\\phpstudy_pro\\WWW\"<br>    <br>    # \u8bbe\u7f6e\u5907\u4efd\u95f4\u9694\uff08\u8fd9\u91cc\u8bbe\u7f6e\u4e3a24\u5c0f\u65f6\uff0c\u537386400\u79d2\uff09<br>    backup_interval = 86400  # 24\u5c0f\u65f6<br>    <br>    # \u5f00\u59cb\u5b9a\u65f6\u5907\u4efd<br>    scheduled_backup(source_dir, dest_dir, backup_interval)<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u8bf4\u660e<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5c06\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u4e3a\u00a0<code>backup_script.py<\/code><\/li>\n\n\n\n<li>\u8fd0\u884c\u811a\u672c\uff1a<code>python backup_script.py<\/code><\/li>\n\n\n\n<li>\u811a\u672c\u4f1a\u6bcf24\u5c0f\u65f6\uff0886400\u79d2\uff09\u6267\u884c\u4e00\u6b21\u5907\u4efd<\/li>\n\n\n\n<li>\u5907\u4efd\u6587\u4ef6\u4f1a\u4fdd\u5b58\u5728\u76ee\u6807\u76ee\u5f55\u4e0b\uff0c\u540d\u79f0\u683c\u5f0f\u4e3a\u00a0<code>wordpress_backup_YYYYMMDD_HHMMSS<\/code><\/li>\n<\/ol>\n\n\n\n<p>\u5982\u679c\u9700\u8981\u4fee\u6539\u5907\u4efd\u9891\u7387\uff0c\u53ef\u4ee5\u8c03\u6574&nbsp;<code>backup_interval<\/code>&nbsp;\u7684\u503c\uff0c\u5355\u4f4d\u4e3a\u79d2\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>3600\u79d2 = 1\u5c0f\u65f6<\/li>\n\n\n\n<li>43200\u79d2 = 12\u5c0f\u65f6<\/li>\n\n\n\n<li>86400\u79d2 = 24\u5c0f\u65f6\uff08\u9ed8\u8ba4\u503c\uff09<\/li>\n<\/ul>\n\n\n\n<p>\u6ce8\u610f\uff1a\u8fd0\u884c\u6b64\u811a\u672c\u9700\u8981\u6709\u8db3\u591f\u7684\u6743\u9650\u8bbf\u95ee\u6e90\u76ee\u5f55\u548c\u5199\u5165\u76ee\u6807\u76ee\u5f55\u3002\u5efa\u8bae\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u547d\u4ee4\u63d0\u793a\u7b26\u6216\u7ec8\u7aef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5b9a\u65f6\u5907\u4efd\u6307\u5b9a\u76ee\u5f55\u7684Python\u811a\u672c\u3002\u5b83\u4f1a\u5c06\u6e90\u76ee\u5f55\u590d\u5236\u5230\u76ee\u6807 <span class=\"readmore\"><a href=\"http:\/\/xc.ipyingshe.net:5347\/?p=6174\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-6174","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6174"}],"version-history":[{"count":1,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6174\/revisions"}],"predecessor-version":[{"id":6175,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/6174\/revisions\/6175"}],"wp:attachment":[{"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6174"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xc.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}