mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #10629 from bcoca/backup_local_exists
backup_local now only tries to back up exising files, returns '' otherwise
This commit is contained in:
commit
e6fa169a05
1 changed files with 11 additions and 7 deletions
|
@ -1297,14 +1297,18 @@ class AnsibleModule(object):
|
|||
|
||||
def backup_local(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:SS~
|
||||
ext = time.strftime("%Y-%m-%d@%H:%M:%S~", time.localtime(time.time()))
|
||||
backupdest = '%s.%s' % (fn, ext)
|
||||
|
||||
try:
|
||||
shutil.copy2(fn, backupdest)
|
||||
except (shutil.Error, IOError), e:
|
||||
self.fail_json(msg='Could not make backup of %s to %s: %s' % (fn, backupdest, e))
|
||||
backupdest = ''
|
||||
if os.path.exists(fn):
|
||||
# backups named basename-YYYY-MM-DD@HH:MM:SS~
|
||||
ext = time.strftime("%Y-%m-%d@%H:%M:%S~", time.localtime(time.time()))
|
||||
backupdest = '%s.%s' % (fn, ext)
|
||||
|
||||
try:
|
||||
shutil.copy2(fn, backupdest)
|
||||
except (shutil.Error, IOError), e:
|
||||
self.fail_json(msg='Could not make backup of %s to %s: %s' % (fn, backupdest, e))
|
||||
|
||||
return backupdest
|
||||
|
||||
def cleanup(self, tmpfile):
|
||||
|
|
Loading…
Reference in a new issue