Copy codeThe Code is as follows :#! /Usr/local/python
Import OS
Import time
Import string
Source = ['/var/www/html/xxx1/', '/var/www/html/xxx2/']
Target_dir = '/backup /'
Target = target_dir + time. strftime ('% Y % m % D ')
Zip_comm = 'zip-r % s % s' % (target, "". join (source ))
Target_database = ['db _ name1', 'db _ name2']
SQL _user = 'root'
SQL _pwd = 'xxx'
If OS. system (zip_comm) = 0:
Print 'file backup Success is: ', target
# If python version is 3.x, print ('file backup Success is: ', target)
Else:
Print 'file backup failed! '
For database_name in target_database:
Target_ SQL = target_dir + database_name + time. strftime ('% Y % m % D') +'. SQL'
SQL _comm = '/usr/local/mysql/bin/mysqldump-u % s-p % s> % s' % (SQL _user, SQL _pwd, database_name, target_ SQL)
If OS. system (SQL _comm) = 0:
Print database_name, 'is backup seccess! '
Else:
Print database_name, 'is backup Failed !! '