脚本介绍:
1)备份源目录的文件
2)目标文件以tar 和bzip2的方式压缩之后放在当前日期文件夹下
4)备份文件以时间注释和执行脚本的用户命名
3)主要用到了时间模块,系统模块,和getpass模块
4)source 可以修改为想备份的目录,因为备份目录一般不经常变动,所以这里写死了
#!/bin/env python
import os
import time
import getpass
source = ['/data/mysql', '/data/mysql/mysql']
target_dir = '/backup/'
user = getpass.getuser()
today = target_dir + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
comment = raw_input('please input comment --> ')
if len(comment) == 0:
target = today + now + '_' + user + '_' + 'tar.bz2'
else:
target = today + now + '_' + comment + '_' + user + '_' + 'tar.bz2'
if not os.p