<commit_before>action :backup do
  # create directory where to index backup files.
  restest = directory "/var/cache/bup" do
    owner "root"
    group "root"
    mode "0755"
    action :create
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)
  
  restest = directory new_resource.backupdir do
    owner "nobody"
    group "nogroup"
    mode "0755"
    action :create
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)
  
  # mount backup server
  restest = mount new_resource.backupdir do
    device "#{new_resource.backupsrv}:#{new_resource.backupdst}"
    fstype "nfs"
    options "rw"
    action [:mount, :enable]
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)
  
  # setting the backup command that cron should run
  bupcmd = "/usr/bin/bup index -f /var/cache/bup/bupindex -ux #{new_resource.name} && /usr/bin/bup -d #{new_resource.backupdir} save -f /var/cache/bup/bupindex -1 -n #{new_resource.bupname} #{new_resource.name}"
 
  # add a command to run before backup
  if new_resource.precmd
    bupcmd = "#{new_resource.precmd} && #{bupcmd}"
  end

  # add a command after backup
  if new_resource.postcmd
    bupcmd = "#{bupcmd} && #{new_resource.postcmd}"
  end

  # encapsulate bupcmd inside paranthesis and send output from cron to a log file
  bupcmd = "(#{bupcmd}) &>> /var/log/cron_output.log"
  # now put the command in a cron.d line
  cronline = "#{new_resource.minute} #{new_resource.hour} #{new_resource.day} #{new_resource.month} #{new_resource.weekday} root #{bupcmd}"

  # schedule backup using a cron.d file
  if ::File.zero? '/etc/cron.d/bup' or not ::File.exists? '/etc/cron.d/bup'
    file '/etc/cron.d/bup' do
      content "# crontab managed by chef\n#{cronline}\n"
    end
    new_resource.updated_by_last_action(true)
  else
    restest = replace_or_add "add crontab line to /etc/cron.d/bup" do
      path "/etc/cron.d/bup"
      pattern Regexp.escape(bupcmd)
      line cronline
    end
    new_resource.updated_by_last_action(restest.updated_by_last_action?)
  end # end if

  restest = file "/etc/logrotate.d/cron_output" do
    action :create
    owner "root"
    group "root"
    mode "0644"
    content "/var/log/cron_output.log {
      missingok
      notifempty
      daily
      rotate 8
      dateext
      compress
      delaycompress
    }\n"
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)

end # end action: backup

action :delete do
  bupcmd = "(/usr/bin/bup index -f /var/cache/bup/bupindex -ux #{new_resource.name} && /usr/bin/bup -d #{new_resource.backupdir} save -f /var/cache/bup/bupindex -1 -n #{new_resource.bupname} #{new_resource.name}) 2>&1 >> /var/log/cron_output.log"
  restest = delete_lines "remove crontab line from /etc/cron.d/bup" do
    path "/etc/cron.d/bup"
    pattern Regexp.escape(bupcmd)
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)

end # end action: delete<commit_msg>changed the line pattern for :backup and :delete<commit_after>action :backup do
  # create directory where to index backup files.
  restest = directory "/var/cache/bup" do
    owner "root"
    group "root"
    mode "0755"
    action :create
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)
  
  restest = directory new_resource.backupdir do
    owner "nobody"
    group "nogroup"
    mode "0755"
    action :create
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)
  
  # mount backup server
  restest = mount new_resource.backupdir do
    device "#{new_resource.backupsrv}:#{new_resource.backupdst}"
    fstype "nfs"
    options "rw"
    action [:mount, :enable]
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)
  
  # setting the backup command that cron should run
  bupcmd = "/usr/bin/bup index -f /var/cache/bup/bupindex -ux #{new_resource.name} && /usr/bin/bup -d #{new_resource.backupdir} save -f /var/cache/bup/bupindex -1 -n #{new_resource.bupname} #{new_resource.name}"
 
  # add a command to run before backup
  if new_resource.precmd
    bupcmd = "#{new_resource.precmd} && #{bupcmd}"
  end

  # add a command after backup
  if new_resource.postcmd
    bupcmd = "#{bupcmd} && #{new_resource.postcmd}"
  end

  # encapsulate bupcmd inside paranthesis and send output from cron to a log file
  bupcmd = "(#{bupcmd}) &>> /var/log/cron_output.log"
  # now put the command in a cron.d line
  cronline = "#{new_resource.minute} #{new_resource.hour} #{new_resource.day} #{new_resource.month} #{new_resource.weekday} root #{bupcmd}"

  # schedule backup using a cron.d file
  if ::File.zero? '/etc/cron.d/bup' or not ::File.exists? '/etc/cron.d/bup'
    file '/etc/cron.d/bup' do
      content "# crontab managed by chef\n#{cronline}\n"
    end
    new_resource.updated_by_last_action(true)
  else
    restest = replace_or_add "add crontab line to /etc/cron.d/bup" do
      path "/etc/cron.d/bup"
      pattern ".*/usr/bin/bup.*-n #{Regexp.escape(new_resource.bupname)} .*"
      line cronline
    end
    new_resource.updated_by_last_action(restest.updated_by_last_action?)
  end # end if

  restest = file "/etc/logrotate.d/cron_output" do
    action :create
    owner "root"
    group "root"
    mode "0644"
    content "/var/log/cron_output.log {
      missingok
      notifempty
      daily
      rotate 8
      dateext
      compress
      delaycompress
    }\n"
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)

end # end action: backup

action :delete do
  restest = delete_lines "remove crontab line from /etc/cron.d/bup" do
    path "/etc/cron.d/bup"
    pattern ".*/usr/bin/bup.*-n #{Regexp.escape(new_resource.bupname)} .*"
  end
  new_resource.updated_by_last_action(restest.updated_by_last_action?)

end # end action: delete
{'fraction_non_alphanumeric': 0.11566141192597669, 'fraction_numerical': 0.005311857436600411, 'mean_word_length': 3.4086102719033233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '5152524', 'n_tokens_mistral': 2126, 'n_tokens_neox': 2098, 'n_words': 487}