用户登录
用户注册

分享至

数据库备份

  • 作者: tm别叫我神经病分明是精神病好么
  • 来源: 51数据库
  • 2022-08-12
#!/usr/bin/python
#_*_encoding:utf-8_*_
#Author:gdlinjianying@qq.com

import os
import time

username = '用户名'
password = R'密码'

target_dir = '/opt/backup/'

today = target_dir + time.strftime('%Y%m%d')

now = time.strftime('%H%M%S')

if not os.path.exists(today):
	os.makedirs(today)
	print 'Successfully created directory', today

target = today + os.sep + now + '.sql'

mysqldump_command = 'mysqldump -u%s -p%s --all-databases > target' % (username, password)

if os.system(mysqldump_command) == 0:
	print 'Successful backup all databases to', target
else:
	print 'Backup failed'
软件
前端设计
程序设计
Java相关