tohuwabohu / puppet-duplicity

Puppet module to manage backups based on duplicity.
Apache License 2.0
8 stars 33 forks source link

Restoring absent directory #118

Closed jlaba closed 10 months ago

jlaba commented 11 months ago

I want to restore a directory (recursive) from backup, if it is not existing. Therefore I have defined this in my manifest:

duplicity::file{'some/directory':
    ensure => present,
}

But how am I dealing with the related

file{ 'some/directory':
  ensure => 'directory',
}

entry? Is it not needed at all? What will happen, if it is the first run and there is no backup so far? (Or it is none available).

How is the thinking in this situation? Most likely it is more a documentation lack, than a software issue.

tohuwabohu commented 10 months ago

Good question! You may not need both but it can be less error prone

  1. the duplicity::file resource will ensure the directory is restored from backup when it is absent
  2. the file resource is usally a good anchor for other resources (like service) and helps to enforce permissions

The biggest risk is that - without explicit relationship - the directory gets created before duplicity::file has had a chance to run and hence prevents the restore from happening. Which in turn can result in the empty directory eventually corrupting the backup.

So what I typically have in my manifests is...

  duplicity::file { $mailman3_data_dir:
    timeout => 1800,
  }

  -> file { $mailman3_data_dir:
    ensure => directory,
    owner  => 'list',
    group  => 'list',
    mode   => '0644',
  }

What will happen, if it is the first run and there is no backup so far? (Or it is none available).

If duplicity::file's ensure is set to present (the default), the directory is missing and there is no backup, the Puppet run will fail as the restore command will fail. This is to prevent silent corruption as mentioned earlier.

jlaba commented 10 months ago

Great! It is working fine. May you add this section to the Readme, so that it is available at puppetforge directly?

tohuwabohu commented 10 months ago

Sure thing. I've updated the README with the example from above. Thanks for the suggestion!