# Some changes in backup mechanism

**URL:** <https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665>\
**Category:** Ansible Project\
**Created:** [October 11, 2013, 8:41pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665 "2013-10-11T20:41:45Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vadim\_Shkolin](https://avatars.discourse-cdn.com/v4/letter/v/ba9def/32.png) [@Vadim\_Shkolin](https://forum.ansible.com/u/Vadim_Shkolin)\
**Post date:** [October 11, 2013, 8:41pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/1 "2013-10-11T20:41:45Z")

</div>

File modules of ansible (“copy”, module and some others) can do backup of changed data. The standard naiming schema (timestamping and adding ‘~’ in original directory) can have bad effects in “conf.d”-like distros.

Main idea: all backups placed into separate directory tree, based on /var/lib/ansible.backups. 1st backup is suffixed by ‘.orig’, 2nd and more later are suffixed by timestamp. This schema is more reliable, and I made patch for it.

New schema example:

/var/lib/ansible.backups/etc/zabbix  
/var/lib/ansible.backups/etc/zabbix/zabbix\_agentd.conf.20130622-172930  
/var/lib/ansible.backups/etc/zabbix/zabbix\_proxy.conf.20130622-172959  
/var/lib/ansible.backups/etc/zabbix/zabbix\_proxy.conf.orig  
/var/lib/ansible.backups/etc/zabbix/zabbix\_agentd.conf.20130614-033941

/var/lib/ansible.backups/etc/zabbix/zabbix\_agentd.conf.orig

Do you interested it? If so, how can I commit this changes into main tree?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [October 11, 2013, 9:10pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/2 "2013-10-11T21:10:19Z")

</div>

Since tasks are run as potentially different users (none of which may have root access), creating a common directory for backups may not work. Most likely, if this were implemented, the backup directory would have to be under the user’s home directory by default.

---

<div class="post-metadata">

**Author:** ![Vadim\_Shkolin](https://avatars.discourse-cdn.com/v4/letter/v/ba9def/32.png) [@Vadim\_Shkolin](https://forum.ansible.com/u/Vadim_Shkolin)\
**Post date:** [October 11, 2013, 11:15pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/3 "2013-10-11T23:15:46Z")

</div>

I think, that mostly all ansible users work as root - native or over sudo. OK, path for backups can be changed.

This is not “if this were implemented”. This is implemented by me :).

Old (native) backup’s mechanism is unusable:

1. It has potential conflict with “conf.d”-like distros
2. There is data overriding when file is modified twice in one playbook, for example, many “lineinfile” step-by-step. The first modification will make backup with pattern %Y-%m-%d@%H:%M~, and the second one will override this backup. Original file will lost, it is a BIG problem for production systems!  
I changed the pattern to %Y%m%d-%H%M%S, and added version number suffix to it, if this file still exists (if step-by-step modifications will be in same second).

I can push this modification into new git branch, and you can check and modify it (add homedir in backup path, etc.), and merge into devel branch.

---

<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:** [October 12, 2013, 12:24am UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/4 "2013-10-12T00:24:07Z")

</div>

I would be interested in seeing and commenting on the pull request.

We can see what it looks like and go from there.

Thanks!

---

<div class="post-metadata">

**Author:** ![Vadim\_Shkolin](https://avatars.discourse-cdn.com/v4/letter/v/ba9def/32.png) [@Vadim\_Shkolin](https://forum.ansible.com/u/Vadim_Shkolin)\
**Post date:** [October 12, 2013, 5:44pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/5 "2013-10-12T17:44:52Z")

</div>

I made the pull request (username: vshkolin)

---

<div class="post-metadata">

**Author:** ![Mike\_Ray](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mike\_Ray](https://forum.ansible.com/u/Mike_Ray)\
**Post date:** [July 31, 2014, 8:09pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/6 "2014-07-31T20:09:01Z")

</div>

What is the status of this? My team would find a feature like this immensely helpful.

It would be additionally useful if you could force it to only maintain X backups in said backup directory.

I see nothing in the changelogs about this.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 31, 2014, 8:16pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/7 "2014-07-31T20:16:24Z")

</div>

Remote backups?

Honestly haven’t had time to attack. I’ll bump the priority though so it doesn’t get lost in the shuffle – it’s a good idea – and an OLD idea 🙂

---

<div class="post-metadata">

**Author:** ![Mike\_Ray](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@Mike\_Ray](https://forum.ansible.com/u/Mike_Ray)\
**Post date:** [July 31, 2014, 8:38pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/8 "2014-07-31T20:38:44Z")

</div>

Yes I did see that it was several months ago… hooray for necro-posting.

But no, I was not suggesting remote backups. Simply put, it would be nice if I could:

1. tell ansible what directory to backup files to ( our playbooks run as root so permissions aren’t a concern for me )
2. tell ansible how many backup files to maintain ( at least in 1.6.2, if I say “backup=yes” and then run a playbook 5 times, there will be 5 backups (assuming the file is changed) )

I’m new so it’d take me awhile, but if there are problems with vshkolin pull request, let me know and perhaps I can re-implement it.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 31, 2014, 9:36pm UTC](https://forum.ansible.com/t/some-changes-in-backup-mechanism/13665/9 "2014-07-31T21:36:16Z")

</div>

Yeah I’ve had this idea for a year and a half it seems.

I’m proposing we do keep the backups on the ansible control machine in a configurable location with a number-to-keep.

When I mean remote, I pretty much mean the control machine vs a delegated host, but that could obviously be a NFS mount.
