Question

I have a backup script that stores the latest backup timestamp in an url like this http://myaws.com/LATEST, the file contains only a string representing the timestamp, for instance, "201402230400". The same script store the real backups in http://myaws.com/201402230400/mycompany-dump-201402230400.gz and http://myaws.com/201402230400/mycompany-data-201402230400.tgz.

The thing is I'm creating a puppet class that will read those urls and restore the files in my new VM based on the LATEST timestamp value. What I'm missing is how can I build a url from a content store in a file?

  define download ($uri, $timeout = 300) {
    exec {
      "download $uri":
      path    => '/usr/bin',
      command => "wget --timestamping -q '$uri' -O $name",
      creates => $name,
      timeout => $timeout
    }
  }

  download {
    "$latest_file":
    uri => "http://myaws.com/LATEST",
    timeout => 900;
  }

  download {
    "$data_file":
    uri => "http://myaws.com/file($latest_file)/mycompany-data-file($latest_file).tgz",
    timeout => 900;
  }

The call file($latest_file) is not working as expected. What I'm doing wrong?

Was it helpful?

Solution

I think you'll want to use generate to get the LATEST timestamp rather than exec inside of a custom type. Something like this perhaps (note that you need to change the format of the uri for the download as well):

$latest_file = generate(
    '/usr/bin/curl',
    '-s',
    'http://myaws.com/LATEST'
)

define download ($uri, $timeout = 300) {
  exec {
    "download $uri":
      path    => '/usr/bin',
      command => "wget --timestamping -q '$uri' -O $name",
      creates => $name,
      timeout => $timeout
  }
}
download {
  "$data_file":
    uri => "http://myaws.com/${latest_file}/mycompany-data-${latest_file}.tgz",
    timeout => 900;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top