-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrbackup.rb
80 lines (68 loc) · 1.82 KB
/
rbackup.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
73
74
75
76
77
78
79
#!/usr/bin/env ruby
# rbackup - remote backup utility - version 3.0 - October 2016
# Copyright © 2011-2016 Giuseppe Cuccu - all rights reserved
# This script is provided AS USED and under constant updating - NO WARRANTY
class RBackup
class << self
attr_reader :config_file, :starting_time, :destinations, :destination,
:server_command
def intro
# @config_file = ENV['HOME']+'/.rbackup.conf'
@config_file = 'conf_test.rb'
@starting_time = Time.now
end
def load_config_file
unless File.file? config_file
puts "Config file #{config_file} not found - creating"
write_conf_file
puts "Config file #{config_file} created - please customize it and try again"
exit 1
end
eval File.read config_file # HACK: refactor better config loader
end
def set_dest
destinations.each do |dest|
if test_destination dest
puts "Destination found: `#{dest}`"
set_destination dest
break
else
puts "Skipping destination `#{dest}`: unreachable"
end
end
abort "Couldn't set destination." if server_command.nil?
end
def test_destination server:nil, port:22, path:nil
if server.nil?
# check local folder
File.directory? path.to_s
else
# test server connection
# TODO: implement
# `nc -zw 10 #{server} #{port} 2> /dev/null && ssh #{server} -p #{port} test -d "#{path}"`
true
end
end
def set_destination server:nil, port:22, path:nil
if server.nil?
# local destination
@server_command = []
@destination = dest
else
# test server connection
# TODO: implement
# `nc -zw 10 #{server} #{port} 2> /dev/null` && system(*server_command, "test", "-d", %Q["#{path}"])
true
end
end
def write_conf_file
end
def main
intro
load_config_file
set_dest
puts starting_time
end
end
end
RBackup::main