python to achieve data and mysql backup on Ubuntu

Python control script on the Ubuntu server deployed today to continue the backup of dataand mysql. Day today, the phone will receive punctual server sent by mail, reports,memory and hard drive information, found that 512 of the memory really is more difficult,the use of memory for a while ran more than 400 M. was thinking about to see if you canrerun a mongodb … it seems really good to study under, although looked mongodb canalso reduce the performance penalty and reduce memory use, the specific django get to say. Say today need to get scheduled backups and mysql python to continue the databackup, this is a must. vps although the RAID10 what, after all, is not readily placed in thehard drive, put the hard drive around maybe Shashi Hou out of the ground broke (my firstremovable hard disk is wrestling reimbursement-_-), another other unpredictable riskswe need every precaution necessary to grasp, to back up your data every day, a weekcan be considered to upload a backup to the mailbox.

Python data backup and mysql, use gzip compression, after all, space is not great, haveto save some flowers. No difficulties on the technical difficulties, mainly or os.systemcalling command to achieve, and then call via crontab scheduled tasks. Code as follows:

# -*- coding:utf-8 -*-
__author__ = 'hjcook'
__blogurl__ = 'http://www.higis.org'

import  time,os

WEBROOT='****'
WEBBACKROOT='****'
FILEFORMAT='%Y%m%d%H%M'

DBUSER='root'
DBPASS='****'
DBNAME='****'
DBBACKROOT='****'

BACKITEMS=[
    'sudo tar -zcvf '+WEBBACKROOT+'blog'+time.strftime(FILEFORMAT)+".tar.gz "+WEBROOT,
    "sudo mysqldump -u%s -p%s --opt %s |gzip >%s" % (DBUSER,DBPASS,DBNAME,DBBACKROOT+'db'+time.strftime(FILEFORMAT)+'.gz')
]

def backData():
    try:
        for item in BACKITEMS:
            print item
            print os.system(item)
    except RuntimeError,e:
        print str(e)

if __name__=="__main__":
    backData()

本文固定链接: http://www.higis.org/en/2012/04/23/python-ubuntu-mysql-databack/ | Hi,GIS


该日志由 H.J 于2012年04月23日发表在 WebServer, Program 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: python to achieve data and mysql backup on Ubuntu | Hi,GIS
关键字: , , ,

python to achieve data and mysql backup on Ubuntu:等您坐沙发呢!

发表评论

快捷键:Ctrl+Enter