Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ You will need to set the following environment variables
to admin
* **PASSWORD** - The password for the above user
* **TZ** - Times default to GMT without a timezone e.g. Australia/Sydney
* **VERIFY_SSL** - Set to false to skip SSL host verificaiton.

You can then control start and stop in two ways, first by setting an hour of the
day
Expand Down
15 changes: 11 additions & 4 deletions hyper
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ class Backup
include HTTParty
format :json

def initialize(dsm, username, password)
def initialize(dsm, username, password, verify_ssl = true)
self.class.base_uri dsm
if !verify_ssl
self.class.default_options.update(verify: false)
end
@sid = login(username, password)
end

Expand Down Expand Up @@ -41,6 +44,7 @@ class Backup

def tasks
params = {
additional: '["last_bkp_result"]',
api: 'SYNO.Backup.Task',
version: 1,
method: 'list',
Expand Down Expand Up @@ -89,23 +93,25 @@ start_hour = ENV['START_HOUR']
end_hour = ENV['END_HOUR']
start_cron = ENV['START_CRON'] || "0 #{start_hour} * * *"
end_cron = ENV['END_CRON'] || "0 #{end_hour} * * *"
verify_ssl = !(ENV['VERIFY_SSL'] == 'false')

puts "Connecting to #{dsm}"
puts "Start Cron: #{start_cron}"
puts "End Cron: #{end_cron}"
puts "Current time: #{Time.now}"

backup = Backup.new(dsm, username, password)
backup = Backup.new(dsm, username, password, verify_ssl)

scheduler = Rufus::Scheduler.new

scheduler.cron(start_cron) do
puts 'Resuming backup tasks'

tasks = backup.tasks
tasks = tasks.select {|t| t['last_bkp_result'] == 'suspend' }

tasks.each do |task|
puts "resuming #{task['task_name']}"
puts "resuming #{task['name']}"
response = backup.resume task['task_id']
puts response
end
Expand All @@ -114,9 +120,10 @@ end
scheduler.cron(end_cron) do
puts 'Suspending backup tasks'
tasks = backup.tasks
tasks = tasks.select {|t| t['last_bkp_result'] == 'backingup' }

tasks.each do |task|
puts "suspending #{task['task_name']}"
puts "suspending #{task['name']}"
response = backup.suspend task['task_id']
puts response
end
Expand Down