首页
工具
心境语句
相册
建站轨迹
关于
Search
1
微信小程序:计算属性的两种体现方式及应用场景
1,646 阅读
2
Antd Upload 组件上传文件接收数据流并下载
1,158 阅读
3
[C#]使用dnSpy对目标程序(EXE或DLL)进行反编译修改并编译运行
635 阅读
4
C#插件火车头采集器动态切换代理IP,及自动切换UserAgent
616 阅读
5
unlock-music工具介绍
572 阅读
react
typecho
ASP
Centos
MYSQL
PHP
Sql server
Javascript
nodejs
数据采集
.NET
git
编程算法
管理及流程
Vue
微信小程序
android
python
mongodb
登录
Search
标签搜索
kotlin
node-sass
nuxtjs
C#火车头插件
火车头采集器
火车头代理
C#反编译
程序逆向
dnSpy教程
Antd
InputNumber
NPM教程
NPM命令
rrweb教程
git慢
git镜像
vim命令
git命令
网页音乐插件
网页播放器
Elysian
累计撰写
74
篇文章
累计收到
0
条评论
首页
栏目
react
typecho
ASP
Centos
MYSQL
PHP
Sql server
Javascript
nodejs
数据采集
.NET
git
编程算法
管理及流程
Vue
微信小程序
android
python
mongodb
页面
工具
心境语句
相册
建站轨迹
关于
搜索到
6
篇与
python
的结果
2022-06-20
利用python和git实现目录文件变更自动备份
前言背景1、主要是突然有一个需要实时备份数据库文件,防止数据丢失的需求,思前想后,发现存在很多方式,例如备份在自己的其他服务器,备份在本地等,最终决定编写一个python脚本用来判断数据库备份文件夹文编改动后通过git提交到github或者gitee代码from watchdog.observers import Observer from watchdog.events import * import time from git import Repo import os def pushgit(ccpath): if(".git" in ccpath): print(1); else: try: dirfile = "C:\\Users\\Administrator\\Documents\\Navicat\\MySQL\\servers\\127.0.0.1\\ddh\\" # code的文件位置,我默认将其存放在根目录下 repo = Repo(dirfile) g = repo.git g.add("--all") g.commit("-m auto update") g.push() print("Successful push!") except : print("error push!") class FileEventHandler(FileSystemEventHandler): def __init__(self): FileSystemEventHandler.__init__(self) def on_moved(self, event): pushgit(event.src_path) if event.is_directory: print("directory moved from {0} to {1}".format(event.src_path,event.dest_path)) else: print("file moved from {0} to {1}".format(event.src_path,event.dest_path)) def on_created(self, event): pushgit(event.src_path) if event.is_directory: print("directory created:{0}".format(event.src_path)) else: print("file created:{0}".format(event.src_path)) def on_deleted(self, event): pushgit(event.src_path) if event.is_directory: print("directory deleted:{0}".format(event.src_path)) else: print("file deleted:{0}".format(event.src_path)) def on_modified(self, event): pushgit(event.src_path) if event.is_directory: print("directory modified:{0}".format(event.src_path)) else: print("file modified:{0}".format(event.src_path)) if __name__ == "__main__": observer = Observer() event_handler = FileEventHandler() observer.schedule(event_handler,"C:\\Users\\Administrator\\Documents\\Navicat\\MySQL\\servers\\127.0.0.1\\ddh\\",True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()centos7 后端运行脚本命令nohup python3 -u auto_up.py > test.log 2>&1 &写好脚本文件中,将脚本文件加入到开机自动运行里就可以监控更新了。然后如果是备份数据库,则只需要创建数据库自动备份计划,就可以完成了。
2022年06月20日
282 阅读
0 评论
0 点赞
1
2