代码需修改三处:
import os import shutil import requests from datetime import datetime # 获取当前日期和时间 current_date = datetime.now().strftime("%Y 年%m 月%d 日") current_time = datetime.now().strftime("%H 点%M 分%S 秒") backup_date = datetime.now().strftime("%Y%m%d") # 用于文件名的简洁日期格式 # 文件路径和压缩包名称(使用日期命名) folder_to_backup = "此处修改路径为自己 bitwarden 的 DATA 文件夹路径" backup_zip = f"/tmp/Bitwarden_{backup_date}.zip" print("[1/4] 开始压缩文件夹...") # 压缩文件夹 shutil.make_archive(backup_zip.replace('.zip', ''), 'zip', folder_to_backup) print(f"[2/4] 文件夹已成功压缩,生成的备份文件:{backup_zip}") # 获取备份文件大小(单位:MB ,保留两位小数) file_size_mb = os.path.getsize(backup_zip) / (1024 * 1024) file_size_text = f"{file_size_mb:.2f}MB" print(f"备份文件大小:{file_size_text}") # Telegram bot 信息 chat_id = "此处修改为自己 telegram 帐号 chat id" bot_token = "此处修改为自己 telegram bot token" telegram_api_url = f"https://api.telegram.org/bot{bot_token}/sendDocument" # 推送文件和文字说明 message_caption = ( f"今日份 Bitwarden 自动备份成功,以下是本次备份的详细信息:\n" f"备份时间:{current_date} {current_time}\n" f"备份大小:{file_size_text}" ) print("[3/4] 开始推送文件到 Telegram...") with open(backup_zip, 'rb') as file: respOnse= requests.post( telegram_api_url, data={'chat_id': chat_id, 'caption': message_caption}, files={'document': file} ) # 检查请求是否成功 if response.status_code == 200: print("[4/4] 备份文件已成功发送到 Telegram !") print(f"推送文件名:Bitwarden_{backup_date}.zip") # 删除本地的 zip 文件 os.remove(backup_zip) print(f"本地备份文件 {backup_zip} 已删除。") else: print(f"[4/4] 推送失败,错误信息:{response.text}")
1 azio7 313 天前 服务端没有需要备份的东西吧,客户端你多端使用,有一端炸了可以用另一端的数据恢复 |
2 aezx 313 天前 有没有邮箱版本? |
![]() | 5 bao3 313 天前 这倒是一个好的解决办法。明天放到我的服务器上 |