[Python] Python 脚本备份sqlserver数据库



import time
import pymssql

nowtime=time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time()))+""

con=pymssql.connect(host='xx.xxx.xx.xx',port=xxx,user='xx',password='xxxx',database='xxxx')
con.autocommit(True)
cur = con.cursor()
sql = "backup database 数据库名 to disk='C:/数据库名_" + nowtime + ".bak'"
cur.execute(sql)
con.autocommit(False)
cur.close()

你可能感兴趣的:(Python)