diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py b/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py index 76a3ba9a9e6debba153e42b654ff210295f3bc05..86e6b0b4a43cf395b63b8035637070af2b30f5ba 100644 --- a/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py +++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/__init__.py @@ -810,5 +810,34 @@ SSLRandomSeed connect builtin configuration_file=mysql_conf_path, )])) self.path_list.extend([mysql_conf_path]) + + # backup configuration + backup_directory = self.createBackupDirectory('mysql') + full_backup = os.path.join(backup_directory, 'full') + incremental_backup = os.path.join(backup_directory, 'incremental') + self._createDirectory(full_backup) + self._createDirectory(incremental_backup) + innobackupex_argument_list = [self.options['innobackupex_binary'], '--defaults-file=%s' % mysql_conf_path, '--socket=%s' %mysql_conf['socket'].strip(), '--user=root'] + environment = dict(PATH=':'.join([self.bin_directory] + os.environ['PATH'].split(':'))) + innobackupex_incremental = zc.buildout.easy_install.scripts([('innobackupex_incremental', + __name__ + '.execute', 'executee')], self.ws, + sys.executable, self.bin_directory, arguments=[ + innobackupex_argument_list + ['--incremental'], + environment])[0] + self.path_list.append(innobackupex_incremental) + innobackupex_full = zc.buildout.easy_install.scripts([('innobackupex_full', + __name__ + '.execute', 'executee')], self.ws, + sys.executable, self.bin_directory, arguments=[ + innobackupex_argument_list, + environment])[0] + self.path_list.append(innobackupex_full) + backup_controller = zc.buildout.easy_install.scripts([('innobackupex_controller', + __name__ + '.innobackupex', 'controller')], self.ws, + sys.executable, self.bin_directory, arguments=[innobackupex_incremental, + innobackupex_full, full_backup, incremental_backup])[0] + self.path_list.append(backup_controller) + mysql_backup_cron = os.path.join(self.cron_d, 'mysql_backup') + open(mysql_backup_cron, 'w').write('0 0 * * * ' + backup_controller) + self.path_list.append(mysql_backup_cron) # The return could be more explicit database, user ... return mysql_conf diff --git a/slapos/recipe/erp5/src/slapos/recipe/erp5/innobackupex.py b/slapos/recipe/erp5/src/slapos/recipe/erp5/innobackupex.py new file mode 100644 index 0000000000000000000000000000000000000000..64872fff2c92f47164fb1e02ca6af227d6caf9f9 --- /dev/null +++ b/slapos/recipe/erp5/src/slapos/recipe/erp5/innobackupex.py @@ -0,0 +1,17 @@ +import os +import glob +def controller(args): + """Creates full backup if not yet found, otherwise uses the newes full one + to perform incremental""" + innobackupex_incremental, innobackupex_full, full_backup, incremental_backup \ + = args + if len(os.listdir(full_backup)) == 0: + print 'Doing full backup in %r' % full_backup + os.execv(innobackupex_full, [innobackupex_full, full_backup]) + backup_list = filter(os.path.isdir, glob.glob(full_backup + "/*")) + backup_list.sort(key=lambda x: os.path.getmtime(x), reverse=True) + base = backup_list[0] + print 'Doing incremental backup in %r using %r as a base' % ( + incremental_backup, base) + os.execv(innobackupex_incremental, [innobackupex_incremental, + '--incremental-basedir=%s'%base, incremental_backup])