#!/usr/bin/env python#script name: backup_ssdb.py#desc: copy /data/ssdb #Time: 2017-08-10 09:58#autho: leiimport osimport datetime,timesource_dir = '/data/ssdb'targat_dir = '/home/ssdb_backup/'now_time = datetime.datetime.now()yes_time = now_time + datetime.timedelta(days=-7)yes_time_nry = yes_time.strftime('%Y%m%d')#copy /data/ssdbcopy_ssdb = 'cp -rf %s %s' % (source_dir,targat_dir)os.system(copy_ssdb)home_ssdb_dir = '%sssdb' % targat_dirif os.path.exists(home_ssdb_dir): target = home_ssdb_dir + time.strftime('%Y%m%d') + '.tar.gz' tar_command = "tar czvf %s %s --exclude=log* --exclude=*log" %(target,source_dir) print tar_command if os.system(tar_command) == 0: print 'Successful backup to',target else: print 'Backup FAILED'else: print 'directory does not exist'#Delete /home/ssdb_backup/ssdbdelete_home_file = '%sssdb' % targat_dirdelete_home_ssdb = 'rm %s -rf ' % delete_home_fileos.system(delete_home_ssdb)#Delete data one day beforeyes_file = 'ssdb%s.tar.gz' % yes_time_nrydelte_dir = targat_dir + yes_filedel_file = 'rm %s -rf ' % delte_diros.system(del_file)