resticprofile icon indicating copy to clipboard operation
resticprofile copied to clipboard

"copy" does not work

Open hgraeber opened this issue 9 months ago • 4 comments

I want to make a two level backup. First level: Make a backup from one or more machines onto an internal backup server. Second level: Make a backup of the backup onto a external disk (or to a cloud repository). For the second level backup I want to run resticprofile with a copy command on the backup server. But the copy command doesn't work as intended.

To make my test easier I have both profiles in on configuration file (data to backup, the first level repo and the second level repo are in one folder). In reality I have to configurations, one on the machines to backup with profile default and one on the backup server with profile secondary.

version: 2

profiles:
  default:
    repository: "repo"
    password-file: repo-secret

    init:

    backup:
      source: "data"
      schedule:
        at: "5:00"

    retention:
      after-backup: true
      keep-within-daily: 7d
      keep-within-weekly: 1m

  secondary:
    repository: "secondary"
    password-file: secondary-secret

    init:
      copy-chunker-params: true
      from-repository: "repo"
      from-password: repo-secret

    copy:
      from-repository: "repo"
      from-password: repo-secret

    forget:
      keep-within-daily: 7d
      keep-within-weekly: 1m

For initialization I run

resticprofile init
resticprofile secondary.init

The backup is run per schedule:

resticprofile backup

And from time to time, normally onto a disk, her into the local secondary repo:

resticprofile secondary.copy

The last step fails (output a little bit edited):

2025/03/16 19:08:29 resticprofile 0.29.1 compiled with go1.24.1
2025/03/16 19:08:29 using configuration file: profiles.yaml
2025/03/16 19:08:29 loading: profiles.yaml
2025/03/16 19:08:29 memory available: 24514MB
2025/03/16 19:08:29 using restic 0.17.3
2025/03/16 19:08:29 profile 'secondary': starting 'copy'
2025/03/16 19:08:29 command environment:
...
2025/03/16 19:08:29 starting command: /usr/bin/restic copy --from-password-file=secondary-secret --from-repo=secondary --verbose=1
repository 02f5638e opened (version 2, compression level auto)
Fatal: Please specify repository location (-r or --repository-file)
2025/03/16 19:08:30 copy on profile 'secondary': exit status 1

I suspect the cause of this is the "Special case" described in "resticprofile > Configuration file > Copy command". There it is described that the "from-" prefix can be omitted. But the "Special Case" somehow reverses "source" and destination, to. restic usually uses --repository and friends for the destination for both the backup and the copy command. resticprofile breaks with this, which isn't a good idea. I there is good reason for this reversal, this shall be done with another special restic command (say reverse-copy) and leave the copy command compatible to the usual restic behavior.

BTW: it would be nice if we can have the retention section work with copy, too. But that's another issue...

hgraeber avatar Mar 16 '25 18:03 hgraeber

Maybe it's a bit confusing in the documentation 🤔 Your configuration is indeed reversed.

The copy section indicates the target of the copy, not where it's copied from.

Your configuration should look like this:

version: 2

profiles:
  default:
    repository: "repo"
    password-file: repo-secret

    init:

    backup:
      source: "data"
      schedule:
        at: "5:00"

    retention:
      after-backup: true
      keep-within-daily: 7d
      keep-within-weekly: 1m

    copy:
      initialize-copy-chunker-params: true
      repository: "secondary"
      password: secondary-secret

  secondary:
    repository: "secondary"
    password-file: secondary-secret

    forget:
      keep-within-daily: 7d
      keep-within-weekly: 1m

creativeprojects avatar Mar 16 '25 21:03 creativeprojects

As I mentioned the default profile is meant to be used on the machine to backup to my backup server and the secondary profile on the backup server to make to copy to the disk. I only merged both into one configuration file for my tests. So the configuration on the backup machine can only work if i use two different profiles for copy and forget. This is not very intuitive:

version: 2

profiles:
  secondary1:
    repository: "repo"
    password-file: repo-secret

    copy:
      repository: "secondary"
      password: secondary-secret

  secondary2:
    repository: "secondary"
    password-file: secondary-secret

    forget:
      keep-within-daily: 7d
      keep-within-weekly: 1m

I think implementing copy different to restics copy is a very bad idea. I prefer to make it behave the same in both programs. I think you have some reason for your change. So you can add a reverse copy function named copy-to instead. Additionally, it would be nice to have after-copy and before-copy entries in the retention-section.

hgraeber avatar Mar 16 '25 22:03 hgraeber

Came here to this issue as I was in the same scenario.

https://creativeprojects.github.io/resticprofile/reference/profile/copy/index.html does not explain this at all.

ilium007 avatar Jun 08 '25 22:06 ilium007

It's documented as a "special case": https://creativeprojects.github.io/resticprofile/configuration/copy/index.html This not very clear. I think that this shall not be fixed with better documentation, but resticprofile shall follow restics semantics.

hgraeber avatar Jun 09 '25 12:06 hgraeber