-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-sync.rb
65 lines (53 loc) · 1.51 KB
/
azure-sync.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
require 'waz-blobs'
#
# Constants for accessing your azure account
#
# access key is the really long guid that is generated
@access_key = ""
# account name is the name of the storage. So buddystore.blob.core.windows.net
# the account name would be buddystore
@account_name = ""
# what is the name of the container you want to put "stuff" in
# I usually use the name of the computer I am on
@main_container_name = ""
#
# helper methods
#
def all_filesystem_files
`ls`.split("\n")
end
def file_type(filename)
`file -Ib #{filename}`.gsub(/\n/,"").split('; ')[0]
end
WAZ::Storage::Base.establish_connection!(:account_name => @account_name, :access_key => @access_key)
#
# Gets the container if it doesn't exist it creates it
#
container = WAZ::Blobs::Container.find(@main_container_name)
if container.nil? then
WAZ::Blobs::Container.create(@main_container_name)
container = WAZ::Blobs::Container.find(@main_container_name)
end
#
# Gets a list of all the new files on the file system
# and is ready to upload them to azure
#
azure_files = container.blobs.map(&:name)
local_files = all_filesystem_files
intersection = azure_files & local_files
final_files = local_files - intersection
final_files.delete("azure-sync.rb")
final_files.delete("README")
final_files.delete("Gemfile")
final_files.delete("Gemfile.lock")
#
# Uploads the new files to azure
#
if final_files.size > 0 then
final_files.each do |f|
container.store(f, File.open(f), file_type(f))
end
puts 'save was successful'
else
puts 'no files to save'
end