from subprocess import Popen, PIPE
from datetime import datetime
# yes, this is me being lazy and not wanting to write a format string.
date = datetime.today().isoformat().split('T')[0]
mysql = "mysqldump -u *username* -p*password* *database* > /usr/local/src/djcode/c2duo_mms/backup-{}.sql".format(date)
gzip = "gzip -c /usr/local/src/djcode/c2duo_mms/backup.sql > /usr/local/src/djcode/c2duo_mms/backup-{}.gz".format(date)
Popen(mysql, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell = True)
Popen(gzip, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell = True)
または、Pythonの古いバージョンのため、
from datetime import datetime
import os
date = datetime.today().isoformat().split('T')[0]
mysql = "mysqldump -u *username* -p*password* *database* > /usr/local/src/djcode/c2duo_mms/backup-%s.sql" % date
gzip = "gzip -c /usr/local/src/djcode/c2duo_mms/backup.sql > /usr/local/src/djcode/c2duo_mms/backup-%s.gz" % date
os.popen3(mysql)
os.popen3(gzip)
出典
2011-08-16 11:04:11
agf
これは正しいです。ありがとう。 – Shehzad009