mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
Move backup to module_common
This commit is contained in:
parent
7c2fe3da16
commit
dfcb9d3c2d
2 changed files with 15 additions and 18 deletions
|
@ -47,6 +47,8 @@ import subprocess
|
|||
import sys
|
||||
import syslog
|
||||
import types
|
||||
import time
|
||||
import shutil
|
||||
|
||||
try:
|
||||
from hashlib import md5 as _md5
|
||||
|
@ -274,6 +276,18 @@ class AnsibleModule(object):
|
|||
infile.close()
|
||||
return digest.hexdigest()
|
||||
|
||||
def backuplocal(self, fn):
|
||||
'''make a date-marked backup of the specified file, return True or False on success or failure'''
|
||||
# backups named basename-YYYY-MM-DD@HH:MM~
|
||||
ext = time.strftime("%Y-%m-%d@%H:%M~", time.localtime(time.time()))
|
||||
backupdest = '%s.%s' % (fn, ext)
|
||||
|
||||
try:
|
||||
shutil.copy2(fn, backupdest)
|
||||
except shutil.Error, e:
|
||||
self.fail_json(msg='Could not make backup of %s to %s: %s' % (fn, backupdest, e))
|
||||
return backupdest
|
||||
|
||||
|
||||
# == END DYNAMICALLY INSERTED CODE ===
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue