From Whipped Dolphin, 5 Months ago, written in Plain Text.
- go back
Embed
Viewing differences between and upload.rb
  1. #!/usr/bin/ruby
  2. # encoding: UTF-8
  3.  
  4. require "trollop"
  5. require 'aws-sdk-s3'
  6. require File.expand_path('../../../lib/recordandplayback', __FILE__)
  7.  
  8. opts = Trollop::options do
  9.   opt :meeting_id, "Meeting id to archive", :type => String
  10.   opt :format, "Playback format name", :type => String
  11. end
  12. meeting_id = opts[:meeting_id]
  13.  
  14. logger = Logger.new("/var/log/bigbluebutton/post_publish.log", 'weekly' )
  15. #logger = Logger.new("/mnt/post_publish.log", 'weekly' )
  16. logger.level = Logger::INFO
  17. BigBlueButton.logger = logger
  18.  
  19. published_files = "/var/bigbluebutton/published/presentation/#{meeting_id}"
  20. #published_files = "/mnt/mam-test"
  21. meeting_metadata = BigBlueButton::Events.get_meeting_metadata("/var/bigbluebutton/recording/raw/#{meeting_id}/events.xml")
  22. #meeting_metadata = BigBlueButton::Events.get_meeting_metadata("/mnt/mam-test/events.xml")
  23.  
  24. def object_uploaded?(s3_client, bucket_name, file, object_key)
  25.   if File.directory?(file)
  26.     response = s3_client.put_object({ bucket: bucket_name, key: object_key })
  27.   else
  28.     data = File.open(file)
  29.     response = s3_client.put_object({ bucket: bucket_name, key: object_key, body: data })
  30.     data.close
  31.   end    
  32.  
  33.   response.etag ? true : false
  34. rescue StandardError => e
  35.   puts "Error uploading object: #{e.message}"
  36.   false
  37. end
  38.  
  39. bucket_name = 'manjuanu-bucket'
  40. region = 'ap-south-1'
  41. s3_client = Aws::S3::Client.new(
  42.   region: region,
  43.   credentials: Aws::Credentials.new('AKIAUOL6MOWTF67HT5VF', 'gUbdk1rVwul1veEh7mM4yxDHShvO3cRl793vxvEQ')
  44. )
  45.  
  46. BigBlueButton.logger.info("S3 Uploader Running for meeting #{meeting_id}")
  47. Dir.glob("#{published_files}/**/*") do |file|
  48.   bucket_file = file.gsub("/var/bigbluebutton/published/presentation/", "")
  49.   if object_uploaded?(s3_client, bucket_name, file, bucket_file)
  50.     BigBlueButton.logger.info("#{bucket_file} uploaded successfully!")
  51.   else
  52.     BigBlueButton.logger.info("#{bucket_file} upload failed!")
  53.   end
  54. end
  55. BigBlueButton.logger.info("S3 Upload completed for meeting #{meeting_id}")
  56.  
  57. exit 0