def setup_tasks(cass): monitor = LoopingCall(cass.monitor_proc, cass.config) deferred = monitor.start(3) deferred.addErrback(error_callback) if cass.config.auto_snapshot: schedule_task(calc_seconds_from_hour(get_backup_hour(cass.config)), cass.take_snapshot) if cass.config.enable_backups: schedule_task(calc_seconds_from_hour(get_backup_hour(cass.config)), cass.take_backup)
def take_backup(self, backup_name=None): """Collect incremental backups and compress.""" LOGGER.debug("[take_backup] called") data_dir = self.data_file_directories if type(data_dir) is list: data_dir = data_dir[0] backup_dir = self.config.backup_dir if os.path.exists(data_dir): if not backup_name: backup_name = datetime.strftime(datetime.now(), "%Y-%m-%dT%H") tar_file = os.path.join(backup_dir, backup_name + '.tar.gz') tar = tarfile.open(tar_file, 'w:gz') for root, dirs, files in os.walk(data_dir): LOGGER.debug("[take_backup] walking [%s] [%s] [%s]", root, dirs, files) if root.split('/')[-1] == 'backups': tar.add(root) tar.close() return schedule_task(calc_seconds_from_hour( get_backup_hour(self.config)), self.take_backup)
def take_snapshot(self): """Perform snapshot operation.""" LOGGER.debug("[take_snapshot] called") if self.clear_snapshot(): command = self._node_tool_command(self._get_hostname(), self.config.jmx_port, 'snapshot') output = self._run_command(command) if not output: return False snapshot_name = re.compile(r'Snapshot directory: (\d+)') matched = self._match_output(output.split('\n'), snapshot_name) if matched: self.latest_snapshot = matched.groups()[0] LOGGER.debug("[take_snapshot] output matched [%s]", self.latest_snapshot) if reactor.running: return reactor.callLater(1, self.verify_snapshot) else: self.verify_snapshot() return schedule_task(calc_seconds_from_hour( get_backup_hour(self.config)), self.take_backup)