This controls if and how files are backed up by cf-agent during file editing operations. If enabled previous versions of the file will be retained next to the file or in default_repository if it is defined in body agent control. Note as it relates to edited files it is only applicable when combined with edit_line. It has no effect when used with edit_template or copy_from.

A value of true (the default behavior) will result in the agent retaining the previous version of the file suffixed with .cf-before-edit.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  body edit_defaults backup( edit_backup )
  {
    edit_backup => "$(edit_backup)";
  }

  bundle agent main
  {
    files:
      "/tmp/example_edit_backup_true"
        create => "true";

      "/tmp/example_edit_backup_true"
        edit_line => insert_lines("Hello World"),
        edit_defaults => backup("true");

    vars:
      "example_files" slist => sort(lsdir( "/tmp/", "example_edit_backup_true.*", false), lex);
      
    reports:
      "$(example_files)";
  }
R: example_edit_backup_true
R: example_edit_backup_true.cf-before-edit

A value of false will result in no retention of the original file.

A value of timestamp will result in the original file be suffixed with the epoch and the canonified form of the date when the file was changed followed by .cf-before-edit. For example _1511292441_Tue_Nov_21_13_27_22_2017.cf-before-edit.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
  body edit_defaults backup( edit_backup )
  {
    edit_backup => "$(edit_backup)";
  }

  bundle agent main
  {
    files:
      "/tmp/example_edit_backup_timestamp"
        create => "true";

      "/tmp/example_edit_backup_timestamp"
        edit_line => insert_lines("Hello World"),
        edit_defaults => backup("timestamp");

    vars:
      "example_files" slist => lsdir( "/tmp/", "example_edit_backup_timestamp.*", false);
      
    reports:
      "$(example_files)";
  }
R: example_edit_backup_timestamp
R: example_edit_backup_timestamp_1511300904_Tue_Nov_21_15_48_25_2017.cf-before-edit

A value of rotate will result in the original file be suffixed with .cf-before-edit followed by an integer representing the nth previous version of the file. The number of rotations is managed by the rotate attribute in edit_defaults.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  body edit_defaults backup( edit_backup )
  {
    edit_backup => "$(edit_backup)";
    rotate => "2";
  }

  bundle agent main
  {
    files:
      "/tmp/example_edit_backup_rotate"
        create => "true";

      "/tmp/example_edit_backup_rotate"
        edit_line => insert_lines("Hello World"),
        edit_defaults => backup("rotate");

      "/tmp/example_edit_backup_rotate"
        handle => "edit_2",
        edit_line => insert_lines("Goodbye"),
        edit_defaults => backup("rotate");

    vars:
      "example_files" slist => lsdir( "/tmp/", "example_edit_backup_rotate.*", false);

    reports:
      "$(example_files)";
  }
R: example_edit_backup_rotate
R: example_edit_backup_rotate.cf-before-edit.1
R: example_edit_backup_rotate.cf-before-edit.2