daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Oct 15th, 2018 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env ruby
  2.  
  3. #$LOAD_PATH << File.expand_path(File.dirname(__FILE__))
  4.  
  5. require 'rubygems'
  6.  
  7. env = ARGV[0] || 'development'
  8. ENV['RAILS_ENV'] = env
  9. puts "Loading environment: #{env}"
  10.  
  11. require File.dirname(__FILE__) + '/../config/boot'
  12. require File.dirname(__FILE__) + '/../config/environment'
  13.  
  14. def connect(environment)
  15.   conf = YAML::load(File.open(File.dirname(__FILE__) + '/../config/database.yml'))
  16.   ActiveRecord::Base.establish_connection(conf[environment])
  17. end
  18.  
  19. # Open ActiveRecord connection
  20. connect(env)
  21.  
  22. puts "STARTED: #{Time.now}"
  23.  
  24. # On sunday, production DB should be exported with all tables and on other days, it should exclude email_charges, perf, vm_daily_rollup tables
  25. if Time.now.friday?
  26. #  export_command = "mysqldump vm accounts addon_rates addons applications audits auth delayed_jobs dhcp disk_layouts email_charges eracent_dsts hadoop host host_groups inventory ip lpars mac non_cloud_items notifications pending perf pkg rates roles roles_users schema_migrations sessions storage_mappings storage_rates system_design_addons system_designs teradata users vdi_requests vm vm_account_audits vm_activities vm_addons vm_daily_rollup vm_images vm_owner vm_owner_audit vsi_activities vsi_requests vsi_templates -h trprcpmysql1.intra.searshc.com -u web -p'rhw&icb' --skip-disable-keys --complete-insert --skip-add-locks --quick --skip-extended-insert --lock-tables=false > /backup/#{Date.today.strftime('%Y-%m-%d')}-full.sql"
  27.   export_command = "mysqldump vm --ignore-table=vm.perf_old  -h prdpdb.global.us.shldcorp.com -P 3372 -u dba -p'*****' --skip-disable-keys --complete-insert --skip-add-locks --quick --skip-extended-insert --lock-tables=false > /shares/backup/#{Date.today.strftime('%Y-%m-%d')}-full.sql"
  28.   del_command = "find /shares/backup/*-full* -maxdepth 1 -type f -mtime +10 -exec rm {} \\;"
  29.   del_msg = "Deleting weekly backup file keeping last 1 only..."
  30. else
  31. #  export_command = "mysqldump vm accounts addon_rates addons applications audits auth delayed_jobs dhcp disk_layouts eracent_dsts hadoop host host_groups inventory ip lpars mac non_cloud_items notifications pending pkg rates roles roles_users schema_migrations sessions storage_mappings storage_rates system_design_addons system_designs teradata users vdi_requests vm vm_account_audits vm_activities vm_addons vm_images vm_owner vm_owner_audit vsi_activities vsi_requests vsi_templates -h trprcpmysql1.intra.searshc.com -u web -p'rhw&icb' --skip-disable-keys --complete-insert --skip-add-locks --quick --skip-extended-insert --lock-tables=false > /backup/#{Date.today.strftime('%Y-%m-%d')}.sql"
  32.   export_command = "mysqldump vm --ignore-table=vm.email_charges --ignore-table=vm.perf --ignore-table=vm.perf_old --ignore-table=vm.vm_daily_rollup -h prdpdb.global.us.shldcorp.com -P 3372 -u dba -p'*****' --skip-disable-keys --complete-insert --skip-add-locks --quick --skip-extended-insert --lock-tables=false > /shares/backup/#{Date.today.strftime('%Y-%m-%d')}.sql"
  33.   del_command = "find /shares/backup/ -maxdepth 1 -type f -mtime +9 -exec rm {} \\;"
  34.   del_msg = "Deleting 10 days older backup files..."
  35. end
  36.  
  37. puts "Exporting Production Cloud Database..."
  38. system(export_command)
  39.  
  40. puts del_msg
  41. system(del_command)
  42.  
  43. puts "Backup of production is Complete."
  44. puts "FINISHED: #{Time.now}"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top