1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
import subprocess
"""
/etc/crontab 中添加定时任务 53 3 * * * root python "/root/py_script/Rclone与AList配合WebDAV同步.py" >/dev/null 2>&1 每天 3:53 执行脚本
测试选项 开启参数"-n, --dry-run" Do a trial run with no permanent changes
只更改 OneDrive 上的文件, 每天自动同步到各个网盘一次 - "_Git Repository backup" 文件夹由 VPS 每星期拉取 GitHub 仓库并备份 - 其他文件夹 ["_WebDAV", "_常用设置留档", "应用"] 是从 OneDrive 上同步
执行流程 - 先把 VPS 上 手动 备份的 ["_Git Repository backup"] 文件夹 从本地 根目录'/' 同步到 OneDrive 根目录'/'下 - 再从 OneDrive 根目录'/' 同步 ["_WebDAV", "_常用设置留档", "应用"] 文件夹 到 本地 根目录'/'下 - 再从 本地 根目录'/' 同步 ["_Git Repository backup", "_WebDAV", "_常用设置留档", "应用"] 文件夹 到 remote_names 的 "/_同步/" 目录下
"""
local_folder = "/etc/alist/storage"
remote_name = "OneDrive" print("===================== Now processed remote: ", remote_name, " =====================")
backup_floders = ["_Git Repository backup"] for backup_floder in backup_floders: print("Now processed floder: ", backup_floder) if backup_floder == "_Git Repository backup": subprocess.run(["rclone", "sync", local_folder + f"/{backup_floder}", f"{remote_name}:/{backup_floder}", "--create-empty-src-dirs", "--check-first", "--progress", "--disable-http-keep-alives"]) else: subprocess.run(["rclone", "sync", local_folder + f"/{backup_floder}", f"{remote_name}:/{backup_floder}", "--create-empty-src-dirs", "--check-first", "--progress", "--ignore-size", "--update", "--disable-http-keep-alives"])
backup_floders = ["_WebDAV", "_常用设置留档", "应用"] for backup_floder in backup_floders: print("Now processed floder: ", backup_floder) if backup_floder == "_Git Repository backup": subprocess.run(["rclone", "sync", f"{remote_name}:/{backup_floder}", local_folder + f"/{backup_floder}", "--create-empty-src-dirs", "--check-first", "--progress", "--disable-http-keep-alives"]) else: subprocess.run(["rclone", "sync", f"{remote_name}:/{backup_floder}", local_folder + f"/{backup_floder}", "--create-empty-src-dirs", "--check-first", "--progress", "--ignore-size", "--update", "--disable-http-keep-alives"])
remote_names = ["谷歌云盘", "阿里云盘Open", "百度网盘", "迅雷云盘", "中国移动云盘"]
backup_floders = ["_Git Repository backup", "_WebDAV", "_常用设置留档", "应用"] for remote_name in remote_names: print("===================== Now processed remote: ", remote_name, " =====================") for backup_floder in backup_floders: print("Now processed floder: ", backup_floder) if backup_floder == "_Git Repository backup": subprocess.run(["rclone", "sync", local_folder + f"/{backup_floder}", f"{remote_name}:/_同步/{backup_floder}", "--create-empty-src-dirs", "--check-first", "--progress", "--disable-http-keep-alives"]) else: subprocess.run(["rclone", "sync", local_folder + f"/{backup_floder}", f"{remote_name}:/_同步/{backup_floder}", "--create-empty-src-dirs", "--check-first", "--progress", "--ignore-size", "--update", "--disable-http-keep-alives"])
print("ALL SYNC DONE!")
|