Merge branch 'backup-common' of https://github.com/dhozac/ansible into devel

This commit is contained in:
Michael DeHaan 2012-09-04 19:45:39 -04:00
commit b97e2a6f5a
4 changed files with 29 additions and 22 deletions

View file

@ -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 ===