发布时间:2019-09-08 09:08:22编辑:auto阅读(1325)
''' 功能:备份文件 版本:1.0 作者:白 ''' import os,time,sys d_dir = '/data/backup/' d_file = 'system_bak.tar.gz' s_dir = ['/etc','/boot','/var/www/html'] date = time.strftime('%Y%m%d') r_dir = d_dir + date + '/' r_name = r_dir + d_file def all_bak(): print('Backup Scripts is Starting!~ Please Waitting......') print('\033[32m------------------------------------------\033[0m') time.sleep(2) if os.path.exists(r_dir) == False: os.makedirs(r_dir) print('The DIR {} create success!'.format(r_dir)) else: print ('The DIR {} is exists!'.format(r_dir)) tar_cmd = 'tar -czvf {} {}'.format(r_name,' '.join(s_dir)) if os.system(tar_cmd) == 0 : #打印绿色输出成功信息!~ print('\033[32mThe backup Files {} exec success!~\033[0m'.format(r_name)) else: print("The backup Files is failed!~") try: if len(sys.argv[1]) == 0: print('\033[34mUsage: {} help|all_bak\033[0m'.format(sys.argv[0])) except IndexError: print('\033[34m----------------------------------\033[0m') print(' ') print('\033[34mUsage: {} Please Exec help|all_bak\033[0m'.format(sys.argv[0])) try: if sys.argv[1] == 'all_bak': all_bak() else: print('\033[34m----------------------------------\033[0m') print('\033[34mUsage: {} Please Exec help|all_bak\033[0m'.format(sys.argv[0])) except IndexError: pass
上一篇: Python 学习笔记 (8)—— sy
下一篇: python 实现将字典写入csv文件
47860
46423
37309
34755
29329
25988
24938
19965
19560
18047
5804°
6430°
5944°
5973°
7078°
5924°
5959°
6453°
6415°
7796°