summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-01-19 19:50:47 -0800
committerGitHub <noreply@github.com>2021-01-19 19:50:47 -0800
commite4dc39b4951dbb698f57300c1790644fbd0b2dc2 (patch)
tree2c2a1ac6df0f22979847ffc5f7291603382e9e3b
parent49ed2516d71e4181d64324a9394b382045f1dcad (diff)
parent33f0b9628f78b4100cfe69addad83070a34fd7f6 (diff)
downloadchef-e4dc39b4951dbb698f57300c1790644fbd0b2dc2.tar.gz
Merge pull request #10894 from kimbernator/master
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/windows_task.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef/resource/windows_task.rb b/lib/chef/resource/windows_task.rb
index 29bade29ce..2fab478738 100644
--- a/lib/chef/resource/windows_task.rb
+++ b/lib/chef/resource/windows_task.rb
@@ -21,6 +21,7 @@ require_relative "../resource"
require_relative "../win32/security" if ChefUtils.windows_ruby?
autoload :ISO8601, "iso8601" if ChefUtils.windows_ruby?
require_relative "../util/path_helper"
+require_relative "../util/backup"
require "win32/taskscheduler" if ChefUtils.windows_ruby?
class Chef
@@ -236,6 +237,10 @@ class Chef
introduced: "14.15", default: false,
description: "To start the task at any time after its scheduled time has passed."
+ property :backup, [Integer, FalseClass],
+ introduced: "17.0", default: 5,
+ description: "Number of backups to keep of the task when modified/deleted. Set to false to disable backups."
+
attr_accessor :exists, :task, :command_arguments
VALID_WEEK_DAYS = %w{ mon tue wed thu fri sat sun * }.freeze
@@ -564,6 +569,7 @@ class Chef
def update_task(task)
converge_by("#{new_resource} task updated") do
+ do_backup
task.set_account_information(new_resource.user, new_resource.password, new_resource.interactive_enabled)
task.application_name = new_resource.command if new_resource.command
task.parameters = new_resource.command_arguments if new_resource.command_arguments
@@ -948,6 +954,11 @@ class Chef
def get_day(date)
Date.strptime(date, "%m/%d/%Y").strftime("%a").upcase
end
+
+ def do_backup
+ file = "C:/Windows/System32/Tasks/#{new_resource.task_name}"
+ Chef::Util::Backup.new(new_resource, file).backup!
+ end
end
action :create do
@@ -1006,6 +1017,7 @@ class Chef
if current_resource.exists
logger.trace "#{new_resource} task exists"
converge_by("delete scheduled task #{new_resource}") do
+ do_backup
ts = ::Win32::TaskScheduler.new
ts.delete(current_resource.task_name)
end