python备份网站,并删除指定日期文件
#!/usr/bin/python
# Filename: backup_ver1.py
import os
import time
import datetime
# 1. The files and directories to be backed up are specified in a list.
source = ['/software/tengine/html/mtax/sbzs','/software/tengine/html/mtax/static']
# If you are using Windows, use source = [r'C:\Documents', r'D:\Work'] or something like that
# 2. The backup must be stored in a main backup directory
target_dir = '/software/tengine/html/mtax/backup/' # Remember to change this to what you will be using
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive
zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
print 'Successful backup to', target
else:
print 'Backup FAILED'
def should_remove(path, pattern, days):
if not path.endswith(pattern):
return False
mtime = os.path.getmtime(path)
now = time.time()
result = now - mtime > days * 24 * 3600
print "\n>>>>>>>>>>>>>>\n"
print "file: ", path
print "mtime: ", datetime.datetime.fromtimestamp(mtime)
print "now: ", datetime.datetime.fromtimestamp(now)
print "> %d days: " % days, result
return result
def findNremove(path, pattern, days):
print "path: ", path
print "pattern: ", pattern
print "days: ", days
for r, d, f in os.walk(path):
for files in f:
file_path = os.path.join(r, files)
if should_remove(file_path, pattern, days):
try:
print "Removing %s" % (file_path)
os.remove(file_path)
except Exception, e:
print e
else:
print "removed %s" % (file_path)
if __name__ == '__main__':
path = os.path.join("/software/tengine/html/mtax/backup/")
days = 30
pattern = ".zip"
findNremove(path, pattern, days)
python备份网站,并删除指定日期文件的更多相关文章
- 定时备份为Sharepoint做网站备份,并删除指定日期的备份
一.创建bat文件 @echo cd \ c: cd "Program Files\Common Files\Microsoft Shared\web server extensions\1 ...
- Debian下自动备份文件并上传到远程FTP服务器且删除指定日期前的备份Shell脚本
说明: 1.备份目录/home/osyunwei下面所有的文件到/home/osyunweibak里面,并且保存为osyunwei20120701.tar.gz的压缩文件格式(2012_07_01是 ...
- 利用任务计划自动删除指定日期的SQLServer备份文件
利用任务计划自动删除指定日期的SQLServer备份文件 命令FORFILES [/P pathname] [/M searchmask] [/S] [/C command] [/D ...
- Linux备份-删除指定日期内文件
#!/usr/bin/env bash source /etc/profile echo " *************** start filter *************** &q ...
- CentOS Linux自动备份MySQL数据库到远程FTP服务器并删除指定日期前的备份Shell脚本
说明: 我这里要把MySQL数据库存放目录/var/lib/mysql下面的pw85数据库备份到/home/mysql_data里面,并且保存为mysqldata_bak_2011_11_03.tar ...
- 【Linux】linux中删除指定日期之前的文件
要删除系统中就的备份文件,就需要使用命令了: #find /tmp -mtime +30 -type f -name *.sh[ab] -exec rm -f {} \; 假如在一个目录中保留最近30 ...
- Mongodb自动备份数据库并删除指定天数前的备份
1.创建Mongodb数据库备份目录 mkdir -p /home/backup/mongod_bak/mongod_bak_now mkdir -p /home/backup/mongod_bak/ ...
- outlook寻找/删除指定日期范围内的邮件
总是收到很多系统预警邮件,时间久了攒了好多垃圾邮件.实际上只需保存近期预警邮件,之前的完全可以删除. 上网找了一圈也没找到方法,然后自己想到了一种,步骤如下: 使用outlook规则,将指定日期范围内 ...
- Inno如何在安装完成时删除指定的文件夹(下的所有文件及子目录)??
删除安装目录下的任意文件夹及下的所有文件及子目录,或者删除指定目录的文件夹,要如何做到呢?谢谢!! //删除文件 用 DeleteFile 只能删除一个文件,不能使用通配符来删除多个文件Dele ...
随机推荐
- B. Divisor Subtraction
链接 [http://codeforces.com/contest/1076/problem/B] 题意 给你一个小于1e10的n,进行下面的运算,n==0 结束,否则n-最小质因子,问你进行多少步 ...
- Visual Studio的安装与单元测试
一.Visual Studio的安装 由于上学期重装了win10系统,以前使用的vc++6.0不能够正常使用,所以直接就安装了Visual Studio 2015,安装的时候就直接按照提示的步骤进行安 ...
- Ubuntu14.04安装PyMuPDF
最近写的一个东西需要将pdf转成图片然后放在网页上展示,找到了个非常好用的轮子叫做PyMuPDF,在windows上测试的时候跑的666,在ubuntu上安装依赖的时候,简直万脸懵逼.github上给 ...
- github使用心得和链接
在本次使用github过程中,刚打开github主界面的时候,吓了一跳,满眼的英文加上各种没用过的命令,真是一个头两个大,废话不多说,下面我就说一下我在使用github过程中遇到的两个问题.: 问题一 ...
- phpstorm 注释模板
/** * Created by ${PRODUCT_NAME}. * User: ${USER} * Date: ${DATE} * Time: ${TIME} */
- [转帖]新的Linux后门开始肆虐 主要攻击中国服务器
新的Linux后门开始肆虐 主要攻击中国服务器 https://www.cnbeta.com/articles/tech/815639.htm 一种新的 Linux 系统后门已经开始肆虐,并主要运行在 ...
- Python文件os模块
一.文件操作 1.打开一个文件 fo = open("foo.txt", "wb") fo.write( "www.runoob.com!\nVery ...
- error launching installer-最新版Win 10 解决方案
error 提示 error launching installer遇到 error的背景 楼主最近重新装了Windows 10 pro 64 bit 版,安装的时候选的地区是United State ...
- 剑指offer:滑动窗口的最大值
滑动窗口的最大值 题目描述 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值.例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值 ...
- python学习笔记十——模块与函数
第五章 模块与函数 5.1 python程序的结构 函数+类->模块 模块+模块->包 函数+类+模块+包=Python pyth ...