about the default_repository

17 views
Skip to first unread message

Neil Watson

unread,
Jun 25, 2015, 3:34:54 PM6/25/15
to help-cfengine
body common control
{
bundlesequence => { "main", };
}

body agent control
{
default_repository => '/tmp/newatson-junk';
}
bundle agent main
{
files:
"/tmp/ssh_config"
create => 'true',
copy_from => local_cp( '/etc/ssh/ssh_config' );
}

body copy_from local_cp ( src )
{
source => ${src};
compare => 'digest';

use_default_repository::
copy_backup => 'timestamp';
}

https://docs.cfengine.com/latest/reference-promise-types-files.html#copy_backup
The reference does not specify what 'timestamp' means. My expected results:

1. Backups will be in the form of /tmp/newatson-junk/ssh_config.<some timestamp>.
2. Backups will not happen unless the class use_default_repository is true.

Now, let's test it on 3.6.5:

$ rm -fr /tmp/ssh_config /tmp/newatson-junk/
$ cf-agent -Kf ./repo.cf
$ ls -ltr /tmp/ssh_config /tmp/newatson-junk/
-rw-r--r-- 1 newatson cad 2047 Jun 25 15:29 /tmp/ssh_config

/tmp/newatson-junk/:
total 0
-rw------- 1 newatson cad 0 Jun 25 15:29 _tmp_ssh_config_cfsaved

Low and behold, a backup that I did not ask for and is not timestamped.
Now, I'll edit /tmp/ssh_config to force a new promise repair and run
cf-agent again:

$ cf-agent -Kf ./repo.cf
$ ls -ltr /tmp/ssh_config /tmp/newatson-junk/
-rw-r--r-- 1 newatson cad 2047 Jun 25 15:31 /tmp/ssh_config

/tmp/newatson-junk/:
total 4
-rw-r--r-- 1 newatson cad 668 Jun 25 15:31 _tmp_ssh_config_cfsaved

A new backup file, that I still did not ask for, and the old one is gone.

How is the default_repository and copy_backup supposed to work?

--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting: https://github.com/evolvethinking/delta_reporting
CFEngine policy: https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3
CFEngine support: http://evolvethinking.com

Neil Watson

unread,
Jun 25, 2015, 4:23:28 PM6/25/15
to help-cfengine
Aleksey set me straight. Backups, copy_from and edit_line, default to
true. So my assumptions were wrong and my reading skills poor :) FYI,
you could do something like this to control backups to be none, normal,
or timestamped:

body edit_defaults efl_empty
{
# Be sure to make a delete promise if you are using timestamp backups.
empty_file_before_editing => 'true';

no_edit_file_backups::
edit_backup => 'false';
edit_file_backups_with_timestamp::
edit_backup => 'timestamp';
}
body copy_from efl_local_cp ( src )
{
# Be sure to make a delete promise if you are using timestamp backups.
source => ${src};
compare => 'digest';

no_copy_from_backups::
copy_backup => 'false';
copy_from_backups_with_timestamp::
copy_backup => 'timestamp';
Reply all
Reply to author
Forward
0 new messages