【python】简单的备份脚本2

根据日期建立文件夹并存放备份的文件。

# 4. The current day is the name of the subdirectory in the main directory

today = target_dir + time.strftime('%Y%m%d%H%M%S')

#print today

# The current time is the name of the zip archive

now = time.strftime('%Y%m%d%H%M%S')

#print now

# Take a comment from the user to create the name of the zip file comment = raw_input('Enter a comment --> ')

if len(comment) == 0: # check if a comment was entered

    target = today + os.sep + now + '.zip'

else:

    target = today + os.sep + now + '_' + \

        comment.replace(' ', '_') + '.zip'

    # Notice the backslash!

# Create the subdirectory if it isn't already there

if not os.path.exists(today):

    os.mkdir(today) # make directory

    print 'Successfully created directory', today

# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive

zip_command = "zip -qr '%s' %s" % (target, source)

#print zip_command

# Run the backup

if os.system(zip_command) == 0:

    print 'Successful backup to', target

else:

    print 'Backup FAILED'

"backup_ver4.py" 42L, 1449C written                                                                                                                  

[yang@rac1 ~]$ python backup_ver2.py

Enter a comment --> yangql

Successfully created directory /tmp/20110723222525

Successful backup to /tmp/20110723222525/20110723222525_yangql.zip

时间: 2024-07-29 04:38:21

【python】简单的备份脚本2的相关文章

Python Mysql自动备份脚本_python

测试系统环境  Windows 2003   python 2.5.1  mysql 5.0.1 应该只适用于Win,因为调用了CMD. 增量备份,因为自用,数据库不大. 回头有了需求加上自检测,5天前的自动删除. #!/usr/bin/env python #encoding=utf-8 #Mysql auto backup #Author:   vane import os, sys, datetime reload(sys) sys.setdefaultencoding('utf-8')

python备份脚本提示文件名,目录或卷标语法出错(Windows7)

问题描述 python备份脚本提示文件名,目录或卷标语法出错(Windows7) 1C #Filename:backup_ver1.py import osimport time #1.the files and directories tobe backed up are specified in a listsource=['D:LibraryPcb''D:LibraryPLD'] target_dir='F:DD' target=target_dir+time.strftime('%Y%m

简单的SQL Server备份脚本代码_MsSql

一般的情况下我们会选用SQL Server自带的数据库维护计划来定义备份. 但有些时候,有的机器数据库维护计划不能成功实现备份.  错误原因可能不尽相同, 这时我们可以用简单的SQL Server备份脚本来做备份. 生成简单的SQL Server备份脚本的SQL语句:   use master   select 'backup database '+name+' to disk=''F:\sqlserver_backup\'+name+'.bak'' with init' from sysdat

linux下简单的备份的脚本 2 【转】

转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4577034    之前写过 linux下简单的备份的脚本 , 最开始一直用着, 后来觉得有必要改进下它了, 不管是从操作方式上还是工作方式上.有这样的想法是因为一次备份引起的. 我经历过磁盘损坏的痛苦, 花了1500元才勉强将数据拯救回来, 于是导致我对备份要求更加高了, 我期望尽量每周备份, 期望备份的目的地是当前系统的完整镜像,也就是说我能够

简单的SQL Server备份脚本代码

一般的情况下我们会选用SQL Server自带的数据库维护计划来定义备份. 但有些时候,有的机器数据库维护计划不能成功实现备份.  错误原因可能不尽相同, 这时我们可以用简单的SQL Server备份脚本来做备份. 生成简单的SQL Server备份脚本的SQL语句:   use master   select 'backup database '+name+' to disk=''F:\sqlserver_backup\'+name+'.bak'' with init' from sysdat

ORACLE数据库的RMAN备份脚本例子

在ORACLE数据库中,RMAN备份的脚本非常多,下面介绍一例shell脚本如何通过RMAN备份,以及FTP上传RMAN备份文件以及归档日志文件的脚本. fullback.sh 里面调用RMAN命令做数据库备份,它使用的cmdfile为/home/oracle/backup/bin/fullback.rcv,同时在/home/oracle/backup/logs目录下生成日志文件. 1: [oracle@DB-Server bin]$ more fullback.sh 2: 3:#!/bin/b

linux服务器本地和百度云备份脚本小试

本地单文件上传脚本,命名uf 这是在本机上做的测试,利用bpcs_uploader脚本实现,只是进行简单的封装,自动完善云端文件路径. 技术要点:使用dirname获取文件所在目录,使用pwd获取文件完整路径,并作为云端文件路径. #!/bin/bash cur_dir=$(cd "$(dirname "$1")"; pwd) name=$(basename "$1") /home/grm/bin/bpcs_uploader/bpcs_uploa

Python批量按比例缩小图片脚本分享

  这篇文章主要介绍了Python批量按比例缩小图片脚本分享,本文直接给出实现代码,需要的朋友可以参考下 图片太大了,上百张图用photoshop改太慢,就想到用python写个简单的批处理.功能简单就是把原图按比例缩小 代码如下: # -*- coding: cp936 -*- import Image import glob, os #图片批处理 def timage(): for files in glob.glob('D:1*.JPG'): filepath,filename = os.

服务器备份脚本

服务器里的数据是相当地重要,要是服务器的数据坏了,没有备份那就玩大了.于是老大让做一个服务器数据备份脚本. 我思考了一下备份策略.定时将服务器里的数据打包通过网络存放到另一台服务器上就可以完成这个功能. 备份有3步骤: (1)收集数据:将服务器里的数据从服务器数据目录复制到指定的目录下. (2)数据打包:用tar将指定目录下的文件打包压缩. (3)发送数据:通过网络将压缩文件发送到另一台服务器.  1. 收集数据     将网站数据复制到指定的目录,假设是/var/backup目录下. Back