resticprofile icon indicating copy to clipboard operation
resticprofile copied to clipboard

Variables in schedule-log only parsed during scheduling of backup jobs

Open ThelloD opened this issue 11 months ago • 2 comments

Summary

The schedule-log parameter in my profile contains variables, for including the date in the log file name (e.g. {{ .Now.Format "2006-01-02" }}). Unfortunately, this variable is parsed during creation of the scheduled backup job, and not every time the scheduled job is executed. Therefore, the name of the log file will include the date when the scheduled job was created, and not the actual execution time stamp.

Question/Issue

Is it possible to parse variables during runtime of the backup job, instead of the time where the backup job was scheduled?

Details

Let's assume my profiles.yaml file is as follows:

version: "2"
profiles:
  myprofile:
    repository: ~/backups/data/{{ .Profile.Name }}

    backup:
      files-from: 
        - ... (cut for brevity)
      tag:
        - mytag
      schedule:
        - "Mon..Fri 17:45"
      schedule-permission: user
      schedule-log: ~/backups/logs/schedule-{{ .Profile.Name }}-{{ .Now.Format "2006-01-02" }}.log

Let's assume I executed resticprofile -n myprofile schedule on March 1, 2024. On Windows, this would create the following scheduled task:

Application: C:\...\resticprofile.exe
Arguments: --no-ansi --config C:\...\profiles.yaml --name mytag --log C:\Users\USERNAME/backups/logs/schedule-myprofile-2024-03-01.log backup

Therefore, the "data" variable in for the --log is lost and replaced by a static value, namely 2024-03-01. Consequently, if the backup job is executed later on, e.g. on April 15, the log file will still remain schedule-myprofile-2024-03-01.log.

ThelloD avatar Mar 12 '24 14:03 ThelloD

Thanks a lot for the detailed report. This will be fixed in #259 where schedules are no longer rendered to a full command line at creation time.

jkellerer avatar Mar 12 '24 16:03 jkellerer

I haven't thought about this case before, but this is indeed a good use of the new run-schedule command 😄

creativeprojects avatar Mar 12 '24 20:03 creativeprojects