<commit_before>rightscale_marker :begin

log "Backup DB2 Database"


log "Running Database Backup"

execute_as_user "create-database" do
  command "db2 backup DB #{node[:db2][:database][:name]} #{node[:db2][:database][:options]}"
  user node[:db2][:instance][:username]
  action :run
end

if node[:backup][:save_to_cloud] == "yes"
  log "Saving Backup to cloud"

  rightscale_tools_gem = `ls /var/cache/rightscale/cookbooks/default/*/cookbooks/rightscale/files/default/rightscale_tools-*.gem`.strip
  
  gem_package "rightscale_tools" do
    source rightscale_tools_gem
    action :install
  end
  
  require "rightscale_tools"
  
  users_home_dir = File.join("/home", node[:db2][:instance][:username])
  backup_files = Dir.entries(users_home_dir).select { |file| file.include?(node[:db2][:database][:name]) }
  newest = backup_files.max { |a,b| (File.mtime(File.join(dir,a)) <=> File.mtime(File.join(dir,b))) }
  
  @ros = RightScale::Tools::ROS.factory(node[:backup][:cloud][:name], node[:backup][:cloud][:key], node[:backup][:cloud][:secret])
  
  @ros.put_object_from_file node[:backup][:bucket], File.join(node[:backup][:path], newest), File.join(users_home_dir, newest)
end

rightscale_marker :end<commit_msg>For testing<commit_after>rightscale_marker :begin

log "Backup DB2 Database"


log "Running Database Backup"

execute_as_user "create-database" do
  command "db2 backup DB #{node[:db2][:database][:name]} #{node[:db2][:database][:options]}"
  user node[:db2][:instance][:username]
  action :run
end

if node[:backup][:save_to_cloud] == "yes"
  log "Saving Backup to cloud"

  rightscale_tools_gem = `ls /var/cache/rightscale/cookbooks/default/*/cookbooks/rightscale/files/default/rightscale_tools-*.gem`.strip
  
  gem_package "rightscale_tools" do
    source rightscale_tools_gem
    action :install
  end
  
  require "rightscale_tools"
  
  users_home_dir = File.join("/home", node[:db2][:instance][:username])
  backup_files = Dir.entries(users_home_dir).select { |file| file.include?(node[:db2][:database][:name]) }
  newest = backup_files.max { |a,b| (File.mtime(File.join(dir,a)) <=> File.mtime(File.join(dir,b))) }
  
  log "Name: #{node[:backup][:cloud][:name]}"
  log "Key: #{node[:backup][:cloud][:key]}"
  log "Secret: #{node[:backup][:cloud][:secret]}"
  @ros = RightScale::Tools::ROS.factory(node[:backup][:cloud][:name], node[:backup][:cloud][:key], node[:backup][:cloud][:secret])
  
  log "Backing up #{File.join(users_home_dir, newest)}"
  @ros.put_object_from_file node[:backup][:bucket], File.join(node[:backup][:path], newest), File.join(users_home_dir, newest)
end

rightscale_marker :end
{'fraction_non_alphanumeric': 0.18140243902439024, 'fraction_numerical': 0.005335365853658537, 'mean_word_length': 6.394366197183099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1557154', 'n_tokens_mistral': 933, 'n_tokens_neox': 932, 'n_words': 154}