Commit 2c3efd8c authored by Romain Courteaud's avatar Romain Courteaud

Configure mydumper automated backup.

parent bb405f53
...@@ -4,7 +4,7 @@ extends = ...@@ -4,7 +4,7 @@ extends =
../cmake/buildout.cfg ../cmake/buildout.cfg
../glib/buildout.cfg ../glib/buildout.cfg
../pcre/buildout.cfg ../pcre/buildout.cfg
../mariadb/buildout.cfg ../mysql-tritonn-5.0/buildout.cfg
parts = mydumper parts = mydumper
...@@ -17,13 +17,13 @@ url = http://launchpad.net/mydumper/0.2/0.2.3/+download/mydumper-0.2.3.tar.gz ...@@ -17,13 +17,13 @@ url = http://launchpad.net/mydumper/0.2/0.2.3/+download/mydumper-0.2.3.tar.gz
md5sum = 36e6a1c97a9634a6882ddaac5e2697d5 md5sum = 36e6a1c97a9634a6882ddaac5e2697d5
buildout-bin-dir = ${buildout:bin-directory} buildout-bin-dir = ${buildout:bin-directory}
cmake-command = ${cmake:location}/bin/cmake cmake-command = ${cmake:location}/bin/cmake
mysql-config = ${mariadb:location}/bin/mysql_config mysql-config = ${mysql-tritonn-5.0:location}/bin/mysql_config
doc-dependency = ${mydumper-doc:eggs} doc-dependency = ${mydumper-doc:eggs}
mysqllib = ${mariadb:location}/lib mysqllib = ${mysql-tritonn-5.0:location}/lib
pkg-config-path = ${glib:location}/lib/pkgconfig/:${pcre:location}/lib/pkgconfig/ pkg-config-path = ${glib:location}/lib/pkgconfig/:${pcre:location}/lib/pkgconfig/
libraries = ${zlib:location}/lib/:${glib:location}/lib/:${pcre:location}/lib/:${mariadb:location}/lib/mysql/ libraries = ${zlib:location}/lib/:${glib:location}/lib/:${pcre:location}/lib/:${mysql-tritonn-5.0:location}/lib/mysql/
includes = ${zlib:location}/include/:${glib:location}/include/:${pcre:location}/include/:${mariadb:location}/include/mysql/ includes = ${zlib:location}/include/:${glib:location}/include/:${pcre:location}/include/:${mysql-tritonn-5.0:location}/include/mysql/
cflags = -I${zlib:location}/include/ -I${glib:location}/include/ -I${pcre:location}/include/ -I${mariadb:location}/include/mysql/ cflags = -I${zlib:location}/include/ -I${glib:location}/include/ -I${pcre:location}/include/ -I${mysql-tritonn-5.0:location}/include/mysql/
slapos_promise = slapos_promise =
directory:bin directory:bin
file:bin/mydumper file:bin/mydumper
...@@ -55,6 +55,7 @@ eggs = ...@@ -55,6 +55,7 @@ eggs =
Sphinx Sphinx
dependent-scripts = true dependent-scripts = true
# XXX-Antoine: here's what I did using hexagonit.recipe.cmmi. # XXX-Antoine: here's what I did using hexagonit.recipe.cmmi.
# and it wasn't working ! # and it wasn't working !
#[mydumper] #[mydumper]
...@@ -66,7 +67,7 @@ dependent-scripts = true ...@@ -66,7 +67,7 @@ dependent-scripts = true
#configure-command = #configure-command =
# ${cmake:location}/bin/cmake \ # ${cmake:location}/bin/cmake \
# -DCMAKE_INSTALL_PREFIX=${:location} \ # -DCMAKE_INSTALL_PREFIX=${:location} \
# -DMYSQL_CONFIG=${mariadb:location}/bin/mysql_config \ # -DMYSQL_CONFIG=${mysql-tritonn-5.0:location}/bin/mysql_config \
# -DCMAKE_INCLUDE_PATH=${zlib:location}/include \ # -DCMAKE_INCLUDE_PATH=${zlib:location}/include \
# -DCMAKE_LIBRARY_PATH=${zlib:location}/lib \ # -DCMAKE_LIBRARY_PATH=${zlib:location}/lib \
# . # .
......
...@@ -88,31 +88,31 @@ class Recipe(slapos.recipe.erp5.Recipe): ...@@ -88,31 +88,31 @@ class Recipe(slapos.recipe.erp5.Recipe):
)) ))
return self.path_list return self.path_list
def installMysqldumpBackup(self): # def installMysqldumpBackup(self):
backup_directory = self.createBackupDirectory('mysqldump') # backup_directory = self.createBackupDirectory('mysqldump')
environment = dict(PATH='%s' % self.bin_directory) # environment = dict(PATH='%s' % self.bin_directory)
executable = os.path.join(self.bin_directory, 'mysqldump') # executable = os.path.join(self.bin_directory, 'mysqldump')
mysql_socket = os.path.join(self.var_directory, 'run', 'mysqld.sock') # mysql_socket = os.path.join(self.var_directory, 'run', 'mysqld.sock')
mysqldump_opt = ['-u', 'root', '-S', mysql_socket, '--single-transaction', # mysqldump_opt = ['-u', 'root', '-S', mysql_socket, '--single-transaction',
'--no-autocommit', '--opt'] # '--no-autocommit', '--opt']
mysqldump_cron = os.path.join(self.cron_d, 'mysqldump') # mysqldump_cron = os.path.join(self.cron_d, 'mysqldump')
database = 'sanef_dms' # database = 'sanef_dms'
cronfile = open(mysqldump_cron, 'w') # cronfile = open(mysqldump_cron, 'w')
cronfile.write("0 0 * * * %(mysqldump)s %(mysqldump_opt)s %(database)s | %(gzip)s > %(destination)s\n" % dict( # cronfile.write("0 0 * * * %(mysqldump)s %(mysqldump_opt)s %(database)s | %(gzip)s > %(destination)s\n" % dict(
mysqldump=executable, mysqldump_opt=' '.join(mysqldump_opt), # mysqldump=executable, mysqldump_opt=' '.join(mysqldump_opt),
database=database, gzip=self.options['gzip_binary'], # database=database, gzip=self.options['gzip_binary'],
destination=os.path.join(backup_directory, '%s.sql.gz' % database) # destination=os.path.join(backup_directory, '%s.sql.gz' % database)
)) # ))
for table in ['message', 'message_queue', 'portal_ids']: # for table in ['message', 'message_queue', 'portal_ids']:
destination = os.path.join(backup_directory, '%s.%s.sql.gz' % (database, # destination = os.path.join(backup_directory, '%s.%s.sql.gz' % (database,
table)) # table))
cronfile.write("0 0 * * * %(mysqldump)s %(mysqldump_opt)s %(database)s %(table)s | %(gzip)s > %(destination)s\n" % dict( # cronfile.write("0 0 * * * %(mysqldump)s %(mysqldump_opt)s %(database)s %(table)s | %(gzip)s > %(destination)s\n" % dict(
mysqldump=executable, mysqldump_opt=' '.join(mysqldump_opt), # mysqldump=executable, mysqldump_opt=' '.join(mysqldump_opt),
database=database, gzip=self.options['gzip_binary'], # database=database, gzip=self.options['gzip_binary'],
table=table, destination=destination) # table=table, destination=destination)
) # )
cronfile.close() # cronfile.close()
self.path_list.append(mysqldump_cron) # self.path_list.append(mysqldump_cron)
def installDevelopmentEnvironment(self): def installDevelopmentEnvironment(self):
ca_conf = self.installCertificateAuthority() ca_conf = self.installCertificateAuthority()
...@@ -161,32 +161,3 @@ class Recipe(slapos.recipe.erp5.Recipe): ...@@ -161,32 +161,3 @@ class Recipe(slapos.recipe.erp5.Recipe):
development_zope='http://%s:%s/' % (ip, zope_port) development_zope='http://%s:%s/' % (ip, zope_port)
)) ))
return self.path_list return self.path_list
def _install(self):
self.path_list = []
self.requirements, self.ws = self.egg.working_set()
# self.cron_d is a directory, where cron jobs can be registered
self.cron_d = self.installCrond()
self.logrotate_d, self.logrotate_backup = self.installLogrotate()
self.killpidfromfile = zc.buildout.easy_install.scripts(
[('killpidfromfile', 'slapos.recipe.erp5.killpidfromfile',
'killpidfromfile')], self.ws, sys.executable, self.bin_directory)[0]
self.path_list.append(self.killpidfromfile)
self.linkBinary()
self.installBT5Repo()
if self.parameter_dict.get('production_mysql', 'false').lower() == 'true':
self.development = False
return self.installProductionMysql()
elif self.parameter_dict.get(
'production_application', 'false').lower() == 'true':
self.development = False
return self.installProductionApplication()
elif self.parameter_dict.get(
'production_frontend', 'false').lower() == 'true':
self.development = False
return self.installProductionFrontend()
elif self.parameter_dict.get('development', 'true').lower() == 'true':
self.development = True
return self.installDevelopmentEnvironment()
else:
raise NotImplementedError('Flavour of instance have to be given.')
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
parts = parts =
publish-mariadb-url publish-mariadb-url
mariadb-instance mariadb-instance
mydumper-import
logrotate logrotate
logrotate-entry-mariadb logrotate-entry-mariadb
cron cron
cron-entry-logrotate cron-entry-logrotate
cron-entry-mariadb-backup cron-entry-mariadb-backup
cron-entry-mariadb-mydumperbackup
binary-link binary-link
eggs-directory = ${buildout:eggs-directory} eggs-directory = ${buildout:eggs-directory}
...@@ -90,6 +92,34 @@ pt-visual-explain-binary = ${perl:siteprefix}/bin/pt-visual-explain ...@@ -90,6 +92,34 @@ pt-visual-explain-binary = ${perl:siteprefix}/bin/pt-visual-explain
xtrabackup-binary = ${xtrabackup:location}/bin/xtrabackup_51 xtrabackup-binary = ${xtrabackup:location}/bin/xtrabackup_51
perl-binary = ${perl:location}/bin/perl perl-binary = ${perl:location}/bin/perl
[mydumper]
recipe = slapos.cookbook:mydumper
wrapper = $${rootdirectory:bin}/raw_mydumper
backup-directory = $${directory:mariadb-backup}
socket = $${mariadb-instance:socket}
user = root
mydumper-binary = ${mydumper:location}/bin/mydumper
database = $${mariadb-instance:database}
import = false
compression = true
[cron-entry-mariadb-mydumperbackup]
<= cron
recipe = slapos.cookbook:cron.d
name = backup
frequency = 0 * * * *
command = $${mydumper:wrapper}
[mydumper-import]
recipe = slapos.cookbook:mydumper
wrapper = $${rootdirectory:bin}/myloader
backup-directory = $${directory:mariadb-backup}
socket = $${mariadb-instance:socket}
user = root
myloader-binary = ${mydumper:location}/bin/myloader
database = $${mariadb-instance:database}
import = true
[logrotate] [logrotate]
recipe = slapos.cookbook:logrotate recipe = slapos.cookbook:logrotate
# Binaries # Binaries
...@@ -167,6 +197,7 @@ crontabs = $${rootdirectory:etc}/crontabs ...@@ -167,6 +197,7 @@ crontabs = $${rootdirectory:etc}/crontabs
cronstamps = $${rootdirectory:etc}/cronstamps cronstamps = $${rootdirectory:etc}/cronstamps
cronoutput = $${basedirectory:log}/cron cronoutput = $${basedirectory:log}/cron
ca-dir = $${rootdirectory:srv}/ssl ca-dir = $${rootdirectory:srv}/ssl
mariadb-backup = $${basedirectory:backup}/mariadb
mariadb-backup-full = $${basedirectory:backup}/mariadb-full mariadb-backup-full = $${basedirectory:backup}/mariadb-full
mariadb-backup-incremental = $${basedirectory:backup}/mariadb-incremental mariadb-backup-incremental = $${basedirectory:backup}/mariadb-incremental
mariadb-data = $${rootdirectory:srv}/mariadb mariadb-data = $${rootdirectory:srv}/mariadb
......
...@@ -61,7 +61,7 @@ command = grep parts ${buildout:develop-eggs-directory}/z2loganalyser.egg-link ...@@ -61,7 +61,7 @@ command = grep parts ${buildout:develop-eggs-directory}/z2loganalyser.egg-link
[template-mariadb] [template-mariadb]
recipe = slapos.recipe.template recipe = slapos.recipe.template
url = ${:_profile_base_location_}/instance-mariadb.cfg url = ${:_profile_base_location_}/instance-mariadb.cfg
md5sum = 17c71c2488d280267ad5130cfa22f52f md5sum = 33a4096149f89d8e36e3709627d9969c
output = ${buildout:directory}/template-mariadb.cfg output = ${buildout:directory}/template-mariadb.cfg
mode = 0644 mode = 0644
......
...@@ -72,6 +72,7 @@ extends = ...@@ -72,6 +72,7 @@ extends =
../component/sed/buildout.cfg ../component/sed/buildout.cfg
../component/coreutils/buildout.cfg ../component/coreutils/buildout.cfg
../component/grep/buildout.cfg ../component/grep/buildout.cfg
../component/mydumper/buildout.cfg
versions = versions versions = versions
...@@ -106,6 +107,7 @@ parts = ...@@ -106,6 +107,7 @@ parts =
zabbix-agent zabbix-agent
pdftk pdftk
dcron dcron
mydumper
# Buildoutish # Buildoutish
eggs eggs
...@@ -476,3 +478,4 @@ setuptools = ...@@ -476,3 +478,4 @@ setuptools =
# official pysvn egg does not supports --include-dirs and # official pysvn egg does not supports --include-dirs and
# --library-dirs, so we use our modified version # --library-dirs, so we use our modified version
pysvn = 1.7.4nxd006 pysvn = 1.7.4nxd006
Sphinx = 1.1.2
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment