Example #1
0
def bakmysql(db_name,sss):
    try:
        global baknum
        baknum=baknum+1
        db_backup_name=r".\data\bakmysql\%s_%s.sql"%(time.strftime("%Y-%m-%d_%H-%M-%S"),db_name)
        if os.path.exists(os.path.dirname(db_backup_name))==False :
            os.makedirs(os.path.dirname(db_backup_name))
        zip_src = db_backup_name
        zip_dest = zip_src + ".zip"
        database.append(zip_dest)

        print("开始备份数据库:%s..."%db_name);
        os.system("mysqldump --skip-comments -h%s -u%s -p%s %s  --default_character-set=%s    > %s" %(db_host, db_user, db_passwd, db_name, db_charset, db_backup_name))
        print("开始压缩数据库:%s..."%db_name)
        #zip_files(zip_src,zip_dest)
        f = zipfile.ZipFile(zip_dest, 'w' ,zipfile.ZIP_DEFLATED)
        f.write(zip_src)
        f.close()
        os.remove(zip_src)
        print("数据库%s备份完成!"% db_name)
        zipsize=os.path.getsize(zip_dest)
        if zipsize<50*1024*1024 :
            print('开始发送邮件...')
            if send_mail(mailto_list,db_name+"数据库备份完成",db_name+"数据库备份完成",zip_dest):
                print ("发送成功")
            else:
                print ("发送失败")
        else:
            print('数据库%s大于(%s)50M不能发送'%(db_name,zipsize))
        baknum=baknum-1
    except:
        baknum=baknum-1
        kl_log.write('备份数据库%s时出错'%db_name,'bakmysql')
Example #2
0
def bakmysql(db_name, sss):
    try:
        global baknum
        baknum = baknum + 1
        db_backup_name = r".\data\bakmysql\%s_%s.sql" % (
            time.strftime("%Y-%m-%d_%H-%M-%S"), db_name)
        if os.path.exists(os.path.dirname(db_backup_name)) == False:
            os.makedirs(os.path.dirname(db_backup_name))
        zip_src = db_backup_name
        zip_dest = zip_src + ".zip"

        print("开始备份数据库:%s..." % db_name)
        os.system(
            "mysqldump -h%s -u%s -p%s %s  --default_character-set=%s    > %s" %
            (db_host, db_user, db_passwd, db_name, db_charset, db_backup_name))
        print("开始压缩数据库:%s..." % db_name)
        #zip_files(zip_src,zip_dest)
        f = zipfile.ZipFile(zip_dest, 'w', zipfile.ZIP_DEFLATED)
        f.write(zip_src)
        f.close()
        os.remove(zip_src)
        print("数据库%s备份完成!" % db_name)
        baknum = baknum - 1
    except:
        baknum = baknum - 1
        kl_log.write('备份数据库%s时出错' % db_name, 'bakmysql')
Example #3
0
def bakmysql(db_name,sss):
    try:
        global baknum
        baknum=baknum+1
        db_backup_name=r".\data\bakmysql\%s_%s.sql"%(time.strftime("%Y-%m-%d_%H-%M-%S"),db_name)
        if os.path.exists(os.path.dirname(db_backup_name))==False :
            os.makedirs(os.path.dirname(db_backup_name))
        zip_src = db_backup_name
        zip_dest = zip_src + ".zip"

        print("开始备份数据库:%s..."%db_name);
        os.system("mysqldump -h%s -u%s -p%s %s  --default_character-set=%s    > %s" %(db_host, db_user, db_passwd, db_name, db_charset, db_backup_name))
        print("开始压缩数据库:%s..."%db_name)
        #zip_files(zip_src,zip_dest)
        f = zipfile.ZipFile(zip_dest, 'w' ,zipfile.ZIP_DEFLATED)
        f.write(zip_src)
        f.close()
        os.remove(zip_src)
        print("数据库%s备份完成!"% db_name)
        baknum=baknum-1
    except:
        baknum=baknum-1
        kl_log.write('备份数据库%s时出错'%db_name,'bakmysql')
Example #4
0
import sys
import urllib
sys.path.append('./lib/')
import kl_log,kl_db,kl_http


if __name__ == '__main__':
    try:
        page=kl_http.kl_http()
        print(page.posturl('http://www.0yuanwang.com'))
        kl_log.write('success')
        input('按任意键继续...')
    except KeyboardInterrupt as e:
        print('程序已经退出')
        print(e)