How to do time-stamping downloads with the JFrog CLI
Time-Stamped Downloads With Artifactory and the JFrog CLIWith download tools such as wget you can get your files to go under time-stamping so that the next time you run a download command or a script it will only download the file if it's newer than the one we already have locally.
Details
This is not a feature directly available with the JFrog CLI as we don't store information on your binaries.
However, using the JFrog CLI along with its File Spec feature to include AQL queries along with a short script, we can achieve virtually the same result.
ResolutionWe may for example create a bash script, which we named tmstpDownload.sh in this case, and add the following one-line script which calls the JFrog CLI (make sure the CLI is in one of the directories in your $PATH, or otherwise adapt the script to pick up the CLI file.):
jfrog rt dl --spec=$3 --spec-vars="time_stamp=$(find $2 -printf "20%Ay-%Am-%Ad" || printf 0);repo="$1";name="$2""
This script takes 3 arguments, referenced in the code as $1, $2, and $3.
$ tmstpDownload.sh <repo name> <artifact name> <spec template>
The first one you see is a "spec template", which is a file spec adapted to take variables from the script. Being that you could adapt this script for as many tasks as you can think of, we decided to make the spec file, as well as the repo and file name, arguments of the script. You may hard code a path if you like, and as long as you have the
{"created":{"$gt":"${time_stamp}"}
part in your AQL it will work, but having both the name and repo as arguments will allow you to flexibly use wildcards for your downloads.
The second argument is the name of the file, and as we mentioned it is passed to the Spec File as a variable. The script also uses this file name to find the timestamp of a local file and find a possible download.
A more efficient way could be to adapt the script to look for the checksum of the present files and search based on that. The AQL fields would be for example "actual_md5", "actual_sha1" or "sha256".
The template is a spec file that takes in variables from the script. In this case, we used the following file which we named template. spec:
{
"files": [{
"aql": {
"items.find" : {
"repo":"${repo}",
"$and": [{
"created":{"$gt":"${time_stamp}"},
"name": {"$match":"${name}"}
}]}}}]}
Being able to choose which template you want to use allows for an incredible amount of flexibility in customization when downloading large numbers of artifacts.
Further Improvements
Just like how we can use wildcards for repo names we could use them for the name, though it would lose the benefit of the time stamping. The script can be rewritten or improved on to allow this type of feature, and at that point, it's up to your creativity. A larger script could allow for more efficient queries that would aggregate all your downloads into one query and check their individual timestamps, but the logic will remain essentially the same.