windows和linux下的python备份脚本
2010-07-20 22:20
477 查看
说两点:
1 windows下如果不指定编码格式他会报乱码错误
Non-ASCII character '/xd6' in file c:/2.py on line 5 说是存在非ASCII字符在文件中,通过网址http://www.python.org/peps/pep-0263.html 查找说
Without interpreter line, using plain text:
# This Python file uses the following encoding: utf-8
import os, sys
加上这种declare的话windows下就可以任意输入汉字而不报错了,注意如果路径包含空格记得用""括起来就可以了
2 ' '.join() 代表把list转换为字符串
WINDOWS:
LINUX:
1 windows下如果不指定编码格式他会报乱码错误
Non-ASCII character '/xd6' in file c:/2.py on line 5 说是存在非ASCII字符在文件中,通过网址http://www.python.org/peps/pep-0263.html 查找说
Without interpreter line, using plain text:
# This Python file uses the following encoding: utf-8
import os, sys
加上这种declare的话windows下就可以任意输入汉字而不报错了,注意如果路径包含空格记得用""括起来就可以了
2 ' '.join() 代表把list转换为字符串
WINDOWS:
# encoding: utf-8 import os import time import sys source = [r'"E:/我 靠"'] target_dir = r'C:/TDDownload' target = target_dir + '//'+ time.strftime('%Y%m%d%H%M%S') + '.zip' zip_command = "zip -qr %s %s" % (target,' '.join(source)) if os.system(zip_command) == 0: print 'sucessful backup',target else: print 'backup failure'
LINUX:
#!/usr/bin/python # -*- coding: uft-8 -*- # Filename: backup_ver1.py import os import time # 1. The files and directories to be backed up are specified in a list. source = ['/home/swaroop/无聊', '/home/swaroop/有趣'] # 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 = '/mnt/e/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'
相关文章推荐
- Linux下通过FTP脚本自动备份数据到windows系统
- 利用Python脚本获取Windows和Linux的系统版本信息 推荐
- 《a byte of python》学习笔记:windows下实现备份的python脚本
- 如何解决Python脚本在Linux和Windows上的格式问题
- windows和ubuntu下使用python写备份脚本
- (windows)python脚本:自动备份并压缩文件,同时删除过期文件
- 使用python在windows 下 编写 自动备份脚本
- linux上mysql日志备份脚本并远程上传至windows ftp服务器
- Python脚本 —Windows下文件备份
- mysql自动备份、恢复脚本(linux的shell、windows的批处理)
- 利用Python编写linux自动备份脚本
- Linux自动定时备份文件夹Python脚本
- (windows)python脚本:自动备份并压缩文件,同时删除过期文件
- Python编写脚本在windows和linux上面出现的错误
- svn的备份与还原怎么用脚本实现svn备份(linux/windows)(转载)
- unix/windows下编写一个python脚本(文件备份)--python学习(4)
- 如何在Windows环境下运行从linux 移植的Python脚本
- windows db2备份至Linux备份服务器之脚本实现
- Python备份脚本——版本一(Windows)
- windows和ubuntu下使用python写备份脚本