#!/usr/bin/ruby # encoding: UTF-8 require "trollop" require 'aws-sdk-s3' require File.expand_path('../../../lib/recordandplayback', __FILE__) opts = Trollop::options do opt :meeting_id, "Meeting id to archive", :type => String opt :format, "Playback format name", :type => String end meeting_id = opts[:meeting_id] logger = Logger.new("/var/log/bigbluebutton/post_publish.log", 'weekly' ) #logger = Logger.new("/mnt/post_publish.log", 'weekly' ) logger.level = Logger::INFO BigBlueButton.logger = logger published_files = "/var/bigbluebutton/published/presentation/#{meeting_id}" #published_files = "/mnt/mam-test" meeting_metadata = BigBlueButton::Events.get_meeting_metadata("/var/bigbluebutton/recording/raw/#{meeting_id}/events.xml") #meeting_metadata = BigBlueButton::Events.get_meeting_metadata("/mnt/mam-test/events.xml") def object_uploaded?(s3_client, bucket_name, file, object_key) if File.directory?(file) response = s3_client.put_object({ bucket: bucket_name, key: object_key }) else data = File.open(file) response = s3_client.put_object({ bucket: bucket_name, key: object_key, body: data }) data.close end response.etag ? true : false rescue StandardError => e puts "Error uploading object: #{e.message}" false end bucket_name = 'manjuanu-bucket' region = 'ap-south-1' s3_client = Aws::S3::Client.new( region: region, credentials: Aws::Credentials.new('AKIAUOL6MOWTF67HT5VF', 'gUbdk1rVwul1veEh7mM4yxDHShvO3cRl793vxvEQ') ) BigBlueButton.logger.info("S3 Uploader Running for meeting #{meeting_id}") Dir.glob("#{published_files}/**/*") do |file| bucket_file = file.gsub("/var/bigbluebutton/published/presentation/", "") if object_uploaded?(s3_client, bucket_name, file, bucket_file) BigBlueButton.logger.info("#{bucket_file} uploaded successfully!") else BigBlueButton.logger.info("#{bucket_file} upload failed!") end end BigBlueButton.logger.info("S3 Upload completed for meeting #{meeting_id}") exit 0