Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backup-rotator.sh should retain at least the last few zip files #7488

Open
1 task done
liuxhit opened this issue Jun 24, 2023 · 1 comment
Open
1 task done

backup-rotator.sh should retain at least the last few zip files #7488

liuxhit opened this issue Jun 24, 2023 · 1 comment
Labels
🎯 feature Categorizes as related to a new feature

Comments

@liuxhit
Copy link

liuxhit commented Jun 24, 2023

Describe the feature

Imagine this scenario:

  1. One day, we deploy gogs, use configuration: BACKUP_INTERVAL=1d BACKUP_RETENTION=7d
  2. Another day after then, for some reason, Gogs was unable to provide services (such as server shutdown), and backup work was suspended
    3.One week after, the administrator fixed the issue and restarted gogs
  3. At this point, the problem occurred: All backup files were deleted by the backup-rotator.sh script because the logic in the script is to find files with mtime seven days ago and delete them all

In fact, although this situation is relatively difficult to occur in production environments (people generally do not allow Gogs to stop serving for more than a week), it may still occur in personal usage scenarios.

Describe the solution you'd like

So, I think we should need a way to keep at least a few of the latest backups, regardless of the time interval, such as we change the logic in backup-rotator.sh(e.g. using a new config indicating the number of backup files we need to keep such as BACKUP_GC_KEEP_NUM=5).

Assume that all files in /backup dir are like: gogs-backup-*.zip, we can maunally find all files(e.g. use ls command with -lthr to find all files and sort by mtime) and keep some of them(e.g. use tail command to select files in pipline instead of the latest 5 files) and delete seleted files.

End up, the original command in script will be llike(not tested):

timeout 60 ls -t "${BACKUP_PATH}/gogs-backup-*.zip" | tail -n +$((${BACKUP_GC_KEEP_NUM} + 1) | xargs -n10 rm

Describe alternatives you've considered

I will find some free time testing if the solution above can run : convert this issue to a pull request ? think of other ways.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@liuxhit liuxhit added the 🎯 feature Categorizes as related to a new feature label Jun 24, 2023
@liuxhit
Copy link
Author

liuxhit commented Jun 25, 2023

push a new PR, try to make it forworld compatibility with existing configuration manual, tested with my own docker-compose.yaml(not modified throughout the upgrade process):

version: '3'
services:
  gogs:
    image: gogs_selfbuild:test
    # image: gogs/gogs
    container_name: gogs
    ports:
      - "xxxxxx:22"
      - "xxxxxx:3000"
    environment:
      - TZ=Asia/Shanghai
      - RUN_CROND=true
      - BACKUP_INTERVAL=1d
      - BACKUP_RETENTION=7d
      - BACKUP_EXTRA_ARGS=--verbose --exclude-mirror-repos
    volumes:
      - "/etc/localtime:/etc/localtime:ro"
      - "/etc/timezone:/etc/timezone:ro"
      - gogs_data:/data
      - gogs_data_backup:/backup
    restart: unless-stopped
    network_mode: "bridge" # or "host" on Linux
volumes:
  gogs_data:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /path/to/the/gogs_data
  gogs_data_backup:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /path/to/the/gogs_data_backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎯 feature Categorizes as related to a new feature
Projects
None yet
Development

No branches or pull requests

1 participant