cupcakearmy / autorestic

Config driven, easy backup cli for restic.
https://autorestic.vercel.app/
Apache License 2.0
1.31k stars 71 forks source link

Prune error when using forget: yes #297

Open ilium007 opened 1 year ago

ilium007 commented 1 year ago

Describe the bug The example config has this option for 'forget': forget: prune # Or only "yes" if you don't want to prune

If I try: forget: yes

I get the error below: invalid value for forget option: 1 Error: 1 errors were found

The below works fine: forget: prune # Or only "yes" if you don't want to prune

Expected behavior Forget should run without pruning

Environment Debian 11

cupcakearmy commented 1 year ago

Interesting, could you try forget: "yes" (with the quotes)

ilium007 commented 1 year ago

That worked. So why does prune not need the quotes?

cupcakearmy commented 1 year ago

Because the yaml library used here interprets the yes as true Probably should handle the case.

pquerner commented 7 months ago

I have "forget" to "prune" in backup command. But I get this error:

backends:
  pcloud2:
    type: rclone
    path: pcloud2:restic_test4
    key: 123
    env: {}
    rest:
      user: ""
      password: ""
    options:
      backup:
        option:
        - rclone.args=serve restic --stdio --verbose
        - rclone.program=/var/services/homes/pascal/rclone
extras:
  log:
    hooks:
      before:
      - 'echo "Starting backup for location: ${AUTORESTIC_LOCATION}"'
      failure:
      - 'echo "Backup failed for location: ${AUTORESTIC_LOCATION}"'
      success:
      - 'echo "Backup successful for location: ${AUTORESTIC_LOCATION}"'
locations:
  projects:
    forget: prune
    from:
    - "/xxx/downloads"
    type: ""
    to:
    - pcloud2
    hooks:
      dir: ""
      prevalidate: []
      before: []
      after: []
      success: []
      failure: []
    cron: ""
    options:
      forget:
        keep-last: 5
      backup:
        exclude:
        - node_modules
        - .git
    copyoption: {}
version: 2
./autorestic_1.8.1_linux_amd64 --verbose -c ./autorestic_configs/autorestic.config.yml --restic-bin $HOME/restic_0.16.4_linux_amd64 backup -a
Using config:    /var/services/homes/pascal/autorestic_configs/autorestic.config.yml
Using lock:  autorestic_configs/.autorestic.lock.yml

    Backing up location "projects"

Backend: pcloud2
> Executing: /var/services/homes/pascal/restic_0.16.4_linux_amd64 backup --option rclone.args=serve restic --stdio --verbose --option rclone.program=/var/services/homes/pascal/rclone --exclude node_modules --exclude .git --tag ar:location:projects /xxx/downloads/
no parent snapshot found, will read all files

Files:           1 new,     0 changed,     0 unmodified
Dirs:            4 new,     0 changed,     0 unmodified
Added to the repository: 1.201 GiB (1.197 GiB stored)

processed 1 files, 1.201 GiB in 4:18
snapshot 03bc4d1c saved

  Forgetting for location "projects"

For backend "pcloud2"
> Executing: /var/services/homes/pascal/restic_0.16.4_linux_amd64 forget --tag ar:location:projects --prune --keep-last 5
exit status 1

Error: 1 errors were found
pascal@Honeycomb:~$
pascal@Honeycomb:~$ /var/services/homes/pascal/restic_0.16.4_linux_amd64 forget --tag ar:location:projects --prune --keep-last 5
Fatal: Please specify repository location (-r or --repository-file)
LM1LC3N7 commented 4 months ago

Hi,

I also have a problem with prune option. Right after the backup log, there is the "forgetting" part and always in error like that:

  Forgetting for location "discourse"

For backend "backblaze"
> Executing: /usr/local/bin/restic forget --tag ar:location:discourse --prune --keep-last 5 --keep-monthly 2 --keep-hourly 0 --keep-yearly 0 --keep-weekly 2 --keep-daily 4
repo already locked, waiting up to 0s for the lock
exit status 1

Config extract:

---
version: 2

extras:
  hooks: &telegram
    before:
      - /home/lmilcent/admin/restic/telegram/start.sh
    failure:
      - /home/lmilcent/admin/restic/telegram/error.sh
    success:
      - /home/lmilcent/admin/restic/telegram/success.sh

#
# Global Config
#
global:
  forget:
    keep-last: 5      # always keep at least 5 snapshots
    keep-daily: 4     # keep 4 last daily snapshots
    keep-weekly: 2    # keep 4 last weekly snapshots
    keep-monthly: 2   # keep 6 last monthly snapshot
    keep-yearly: 0    # keep 1 last yearly snapshot
    keep-hourly: 0    # keep 3 last hourly snapshots
    #keep-within: '2w' # keep snapshots

locations:
  home:
    from:
      - /home
    to:
      - backblaze
    cron: '0 0 * * *' # Every days at 00:00 (incremental snapshots)
    forget: "prune"
    # Hooks defined in default on top of file
    hooks:
      <<: *telegram
    options:
      backup:
        tag: home
        exclude:
          - .cache/
          - .autorestic.lock.yml
          - .local/
FunctionDJ commented 4 months ago

I have the same issue with an SFTP backend:

$ autorestic forget -av
Using config paths: . /home/function /home/function/.config/autorestic
Using config:    /home/function/.autorestic.yml
Using lock:      /home/function/.autorestic.lock.yml

  Forgetting for location "data"  

For backend "truenas"
> Executing: /usr/local/bin/restic forget --tag ar:location:data --keep-yearly 4 --keep-monthly 4 --keep-daily 4 --keep-weekly 4
repo already locked, waiting up to 0s for the lock
Error: exit status 1

I tried autorestic unlock which didn't show any error but didn't fix the issue so i think a repo lock is not the issue.

Edit: restic unlock appears to have fixed the issue. Not sure why autorestic unlock didn't fix it.

pew commented 4 months ago

@FunctionDJ I had the same issue and tried autorestic unlock with no success, however autorestic exec -b my-backend -- unlock fixed it. Looks like the first unlock command handles a running restic process on the system, and the latter actually unlocks the remote repoistory.

FunctionDJ commented 4 months ago

@pew wow if i had known about autorestic exec that would saved me a bunch of typing and pasting.

i wonder why the two behave differently. i assumed autorestic unlock is supposed to do at least the same as restic unlock.

LM1LC3N7 commented 4 months ago

@FunctionDJ I had the same issue and tried autorestic unlock with no success, however autorestic exec -b my-backend -- unlock fixed it. Looks like the first unlock command handles a running restic process on the system, and the latter actually unlocks the remote repoistory.

Thanks for the workaround! It saved me more than 1.2Tb of backup data. From 1.7Tb to 290Gb stored! My backblaze billing was growing and I did not understand why, as the forget option in autorestic was enabled.

I hope this bug will be solved soon, or this is just an "historic" issue, as I am using autorestic for years now. Thanks @cupcakearmy for the tool, I absolutely love ❤️

ilium007 commented 4 months ago

I was also getting the repo lock error when running a prune. I have had to seperate my scheduled backup tasks into two seperate jobs to overcome the lock issue.