python 备份文件脚本

使用python备份服务器的文件

#coding=utf-8
import os 
import os.path

def copyFiles(sourceDir, targetDir): 
for file in os.listdir(sourceDir): 
sourceFile = os.path.join(sourceDir, file) 
targetFile = os.path.join(targetDir, file) 
if os.path.isfile(sourceFile): 
if not os.path.exists(targetDir): 
os.makedirs(targetDir) 
if not os.path.exists(targetFile) or (os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))): 
open(targetFile, "wb").write(open(sourceFile, "rb").read()) 
if os.path.isdir(sourceFile): 
First_Directory = False 
copyFiles(sourceFile, targetFile)
print copyFiles("/home/user/Application/tomcat/apache-tomcat-8.0.30/wtpwebapps/CLZ/static/upload/", "./")

ubuntu 环境设置定时任务

crontab -e 配置定时任务

sudo service cron start 启动任务

sudo service cron stop 停止任务

原文地址:https://www.cnblogs.com/guoke-jsp/p/5341073.html