mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
Windows: Add backup parameter to modules (#50033)
* Windows: Add backup parameter to modules This PR adds a backup infrastructure for modules. * Fixes based on review feedback * Various fixes to check-mode and backup * Add integration tests * Fix win_xml integration test * Add backup support to copy action plugin * Added integration tests * Improve test efficiencies and other minor impv
This commit is contained in:
parent
76b5a9fb52
commit
3d1dd0e599
15 changed files with 365 additions and 95 deletions
|
@ -0,0 +1,33 @@
|
|||
# Copyright (c): 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
|
||||
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
|
||||
Function Backup-File {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Helper function to make a backup of a file.
|
||||
.EXAMPLE
|
||||
Backup-File -path $path -WhatIf:$check_mode
|
||||
#>
|
||||
[CmdletBinding(SupportsShouldProcess=$true)]
|
||||
|
||||
Param (
|
||||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
|
||||
[string] $path
|
||||
)
|
||||
|
||||
Process {
|
||||
$backup_path = $null
|
||||
if (Test-Path -LiteralPath $path -PathType Leaf) {
|
||||
$backup_path = "$path.$pid." + [DateTime]::Now.ToString("yyyyMMdd-HHmmss") + ".bak";
|
||||
Try {
|
||||
Copy-Item -LiteralPath $path -Destination $backup_path
|
||||
} Catch {
|
||||
throw "Failed to create backup file '$backup_path' from '$path'. ($($_.Exception.Message))"
|
||||
}
|
||||
}
|
||||
return $backup_path
|
||||
}
|
||||
}
|
||||
|
||||
# This line must stay at the bottom to ensure all defined module parts are exported
|
||||
Export-ModuleMember -Function Backup-File
|
Loading…
Add table
Add a link
Reference in a new issue