<commit_before>module Backup
  class Performer
    attr_reader :storage, :config

    def perform_backup(storage, config)
      @storage = storage
      @config = config
      @started_at = Time.now.utc
      @timestamp = @started_at.strftime('%s - %A %d %B %Y %H:%M')
      storage.open
      make_tmp_dir
      backup_mysql if Backup.features.mysql_installed?
      backup_mongodb if Backup.features.mongodb_installed?
      backup_directories
      backup_files
      cleanup_old_backups
    ensure
      remove_tmp_dir
      storage.close
    end

  protected

    def backup_directories
      config.get(:directories).each do |name, dir|
        dir_filename  = "#{name}.tar.xz"
        dir_fileparam = Shellwords.escape(dir_filename)
        cmd = "cd #{dir} && /usr/bin/env XZ_OPT=-3 tar -cJvf #{tmp_path}/#{dir_fileparam} ."
        puts "Exec #{cmd}"
        system(cmd)
        storage.upload("#{@timestamp}/#{dir_filename}", "#{tmp_path}/#{dir_filename}")
      end
    end

    def backup_files
      config.get(:files).each do |name, files|
        begin
          files_tmp_path   = File.join(tmp_path, "#{name}-tmp")
          file_bunch_name  = "#{name}.tar.xz"
          file_bunch_param = Shellwords.escape(file_bunch_name)

          FileUtils.mkdir_p(files_tmp_path)
          FileUtils.cp(files.select { |el| File.exists?(el) }, files_tmp_path)

          cmd = "cd #{files_tmp_path} && /usr/bin/env XZ_OPT=-3 tar -cJvf #{tmp_path}/#{file_bunch_param} ."
          system(cmd)<commit_msg>Disable compression for dirs and files<commit_after>module Backup
  class Performer
    attr_reader :storage, :config

    def perform_backup(storage, config)
      @storage = storage
      @config = config
      @started_at = Time.now.utc
      @timestamp = @started_at.strftime('%s - %A %d %B %Y %H:%M')
      storage.open
      make_tmp_dir
      backup_mysql if Backup.features.mysql_installed?
      backup_mongodb if Backup.features.mongodb_installed?
      backup_directories
      backup_files
      cleanup_old_backups
    ensure
      remove_tmp_dir
      storage.close
    end

  protected

    def backup_directories
      config.get(:directories).each do |name, dir|
        dir_filename  = "#{name}.tar"
        dir_fileparam = Shellwords.escape(dir_filename)
        cmd = "cd #{dir} && /usr/bin/env tar -cvf #{tmp_path}/#{dir_fileparam} ."
        puts "Exec #{cmd}"
        system(cmd)
        storage.upload("#{@timestamp}/#{dir_filename}", "#{tmp_path}/#{dir_filename}")
      end
    end

    def backup_files
      config.get(:files).each do |name, files|
        begin
          files_tmp_path   = File.join(tmp_path, "#{name}-tmp")
          file_bunch_name  = "#{name}.tar"
          file_bunch_param = Shellwords.escape(file_bunch_name)

          FileUtils.mkdir_p(files_tmp_path)
          FileUtils.cp(files.select { |el| File.exists?(el) }, files_tmp_path)

          cmd = "cd #{files_tmp_path} && /usr/bin/env tar -cvf #{tmp_path}/#{file_bunch_param} ."
          system(cmd)
{'fraction_non_alphanumeric': 0.12072968490878938, 'fraction_numerical': 0.0006633499170812604, 'mean_word_length': 2.616306954436451, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3840841', 'n_tokens_mistral': 1005, 'n_tokens_neox': 987, 'n_words': 188}