代码拉取完成,页面将自动刷新
同步操作将从 oO小飞Oo/python_auto_backup_mysql 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import os,time,datetime,threading
global timer
def auto_time():
auto_backup()
timer=threading.Timer(3600,auto_time)
timer.start()
def auto_backup():
DB_HOST = '127.0.0.1'
DB_USER = 'root'
DB_USER_PASSWORD = 'abc123'
DB_NAME = 'ldsg_s25'
BACKUP_PATH = '/bk/'
FILE_NAME = time.strftime('%m%d%Y-%H%M%S')
TODAYBACKUPPATH = BACKUP_PATH + time.strftime('%m%d%Y')
print "creating backup folder"
if not os.path.exists(TODAYBACKUPPATH):
os.makedirs(TODAYBACKUPPATH)
print "checking for databases names file."
if os.path.exists(FILE_NAME):
file1 = open(FILE_NAME)
multi = 1
print "Databases file found..."
print "Starting backup of all dbs listed in file " + DB_NAME
else:
print "Databases file not found..."
print "Starting backup of database " + DB_NAME
multi = 0
if multi:
in_file = open(FILE_NAME,"r")
flength = len(in_file.readlines())
in_file.close()
p = 1
dbfile = open(FILE_NAME,"r")
while p <= flength:
db = dbfile.readline() # reading database name from file
db = db[:-1] # deletes extra line
dumpcmd = "mysqldump -u " + DB_USER + " -p" + DB_USER_PASSWORD + " " + db + " > " + TODAYBACKUPPATH+"/"+FILE_NAME +"_"+ db + ".sql"
os.system(dumpcmd)
p = p + 1
dbfile.close()
else:
db = DB_NAME
dumpcmd = "mysqldump -u " + DB_USER + " -p" + DB_USER_PASSWORD + " " + db + " > " + TODAYBACKUPPATH+"/"+ FILE_NAME +"_"+ db + ".sql"
os.system(dumpcmd)
print "Backup script completed"
print "Your backups has been created in '" + TODAYBACKUPPATH + "' directory"
auto_time()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。