# Change module.backup\_local behaviour

**URL:** <https://forum.ansible.com/t/change-module-backup-local-behaviour/12660>\
**Category:** Ansible Project\
**Created:** [April 11, 2013, 8:18am UTC](https://forum.ansible.com/t/change-module-backup-local-behaviour/12660 "2013-04-11T08:18:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glaurent](https://avatars.discourse-cdn.com/v4/letter/g/e9bcb4/32.png) [@glaurent](https://forum.ansible.com/u/glaurent)\
**Post date:** [April 11, 2013, 8:18am UTC](https://forum.ansible.com/t/change-module-backup-local-behaviour/12660/1 "2013-04-11T08:18:04Z")

</div>

Hi,

Still discovering Ansible, … and Python by the way, well…

I’m rewriting the lineinfile module to match my enterprise’s needs, and I have an issue with the backup function.

We want to backup file, with our standard time-stamp, aka %file%.YYYYMMDD

I found the original module.backup\_local function in ./lib/ansible/module\_common.py, which use only one time-stamp format:

> ext = time.strftime(“%Y-%m-%d@%H:%M~”, time.localtime(time.time()))

I try the replace the call to this function by my own function… need to figure how to do it, learning Python…

**1/** Is there already something plan to customize the backup time-stamp ?

**2/** Is it possible to add a overcharged backup\_local function, allowing to specify the time-stamp ?

> def backup\_local(self, fn, **tsf** ):  
> ‘’‘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( **tsf** , 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

Regards,

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [April 12, 2013, 1:57pm UTC](https://forum.ansible.com/t/change-module-backup-local-behaviour/12660/2 "2013-04-12T13:57:01Z")

</div>

There is no plan to make the backup timestamp configurable.

I imagine at some point there will be support for a server-side automatic backup for file/copy operations, this is obviously just a local copy.
