Sunday, January 25, 2015

mysqlbackup py 3

root@server:~/hhscpy# cat sqlbackup.py
#!/usr/bin/python
backup_dest = '/root/sqlbackup/'
import os
import time
import datetime
dbhost = 'localhost'
dbuser = 'root'
dbpass = 'hotti@90'
datetime = time.strftime("%Y-%m-%d_%H-%M-%S")
backuppathwithDT = backup_dest + datetime
multi=2
#create directory if it does not exist
if not os.path.exists(backuppathwithDT):
    os.makedirs(backuppathwithDT, 0500)
print "Checking for db names in file"
print "starting backup of databases.. "
#Starting backup
if multi:
        dumpcmd = "mysqldump -u " + dbuser + " -p" + dbpass + " --all-databases --events " + " > " + backuppathwithDT + "/completedb.sql"
        os.system(dumpcmd)
else:
    print "no database to dump"
print "Backup complete..."
root@server:~/hhscpy# cat sqlbackup.py
#!/usr/bin/python
backup_dest = '/root/sqlbackup/'
import os
import time
import datetime
dbhost = 'localhost'
dbuser = 'root'
dbpass = 'p@$$word'
datetime = time.strftime("%Y-%m-%d_%H-%M-%S")
backuppathwithDT = backup_dest + datetime
multi=2
#create directory if it does not exist
if not os.path.exists(backuppathwithDT):
    os.makedirs(backuppathwithDT, 0500)
print "Checking for db names in file"
print "starting backup of databases.. "
#Starting backup
if multi:
        dumpcmd = "mysqldump -u " + dbuser + " -p" + dbpass + " --all-databases --events " + " > " + backuppathwithDT + "/completedb.sql"
        os.system(dumpcmd)
else:
    print "no database to dump"
print "Backup complete..."

No comments:

Post a Comment