''' 功能:备份文件 版本: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 |