-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfy_pull_rename_lego_mass_export.rb
72 lines (65 loc) · 3.31 KB
/
bfy_pull_rename_lego_mass_export.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env ruby
# script to pull in CSV sheet (delimited by commas) with service export information, copy and rename to 'export_upload' directory
# usage: make an executable '.rb' file in linxu cli and run, will prompt for file location of CSV file
require 'csv'
def perform
puts "Please enter file path and file name of such as /root/nguarino/serviceExportInfo.csv to a CSV file that is comma delimited: "
csv_file = gets.chomp
service_export_info = CSV.read("#{csv_file}")
puts "Please list the customer ID of the account you need to pull export files from: "
customer_id = gets.chomp
counter = service_export_info.count
grab_rename_store_zipfile(service_export_info, customer_id)
puts "script has finished running"
end
def grab_rename_store_zipfile(serv_exp_info, cid)
counter = serv_exp_info.count
serv_exp_info.each do |e|
puts "#{counter} entries left to iterate through"
app_type = e[0]
name = e[1].split
email = e[2]
last_backup_date = e[3]
export_zip_name = e[4]
mailbox = e[5]
sp_name = e[6]
if last_backup_date == "NULL"
counter = counter - 1
puts "attempting to copy #{e}"
puts "no valid snapshot so wasn't exported, next"
next
else
if app_type == "Office365Exchange" || app_type == "Office365OneDrive"
counter = counter - 1
puts "attempting to copy #{e}"
if File.exists?("/datto/array1/bfyData/#{cid}/export_upload/#{app_type}_#{name[0]}_#{name[1]}.zip")
puts "file already exists, next"
next
end
system("cp /datto/array1/bfyData/#{cid}/#{app_type}/exports/#{export_zip_name}.zip /datto/array1/bfyData/#{cid}/export_upload/#{app_type}_#{name[0]}_#{name[1]}.zip")
puts "export file copied and renamed from export directory into export_upload directory, moving to next export file"
end
if app_type == "Office365Teams"
counter = counter - 1
puts "attempting to copy #{e}"
if File.exists?("/datto/array1/bfyData/#{cid}/export_upload/#{app_type}_#{mailbox}.zip")
puts "file already exists, next"
next
end
system("cp /datto/array1/bfyData/#{cid}/#{app_type}/exports/#{export_zip_name}.zip /datto/array1/bfyData/#{cid}/export_upload/#{app_type}_#{mailbox}.zip")
puts "export file copied and renamed from export directory into export_upload directory, moving to next export file"
end
if app_type == "Office365SharePoint"
counter = counter - 1
puts "attempting to copy #{e}"
if File.exists?("/datto/array1/bfyData/#{cid}/export_upload/#{app_type}_#{sp_name}.zip")
puts "file already exists, next"
next
end
system("cp /datto/array1/bfyData/#{cid}/#{app_type}/exports/#{export_zip_name}.zip /datto/array1/bfyData/#{cid}/export_upload/#{app_type}_#{sp_name}.zip")
puts "export file copied and renamed from export directory into export_upload directory, moving to next export file"
end
end
end
end
perform