Skip to content

Commit

Permalink
Switch to croniter for cron validation
Browse files Browse the repository at this point in the history
  • Loading branch information
enyachoke committed Nov 5, 2024
1 parent a34733e commit 7682500
Show file tree
Hide file tree
Showing 15 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ venv
/private/
restic_data/
restic_cache/
restored_filestores
live_two_filestores
alerts.env

# build
Expand Down
2 changes: 0 additions & 2 deletions docker-compose-backup-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ services:
- ./restic_data:/restic_data
# Map restic cache
- ./restic_cache:/cache
# Map in project source in dev
- ./src:/restic-compose-backup
networks:
global:
external: true
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ services:
restic-compose-backup.volumes: true
restic-compose-backup.volumes.include: "/tests"
volumes:
- ./restored_filestores/src/tests:/srv/tests
- ./restored_filestores/.vscode:/srv/code
- ./live_two_filestores/src/tests:/srv/tests
- ./live_two_filestores/.vscode:/srv/code
environment:
- SOME_VALUE=test
- ANOTHER_VALUE=1
Expand All @@ -24,8 +24,8 @@ services:
restic-compose-backup.volumes: true
restic-compose-backup.volumes.exclude: "/tests"
volumes:
- ./restored_filestores/src/tests:/srv/tests
- ./restored_filestores/.vscode:/srv/code
- ./live_two_filestores/src/tests:/srv/tests
- ./live_two_filestores/.vscode:/srv/code
environment:
- SOME_VALUE=test
- ANOTHER_VALUE=1
Expand Down
2 changes: 1 addition & 1 deletion restic_compose_backup.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RESTIC_KEEP_MONTHLY=12
RESTIC_KEEP_YEARLY=3

LOG_LEVEL=info
CRON_SCHEDULE=0,5,10,15,20,25,30,35,40,45,50,55 * * * *
CRON_SCHEDULE=*/5 * * * *

# EMAIL_HOST=
# EMAIL_PORT=
Expand Down
2 changes: 0 additions & 2 deletions restore-backup.sh

This file was deleted.

1 change: 0 additions & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ RUN apk update && apk add python3 \
py3-pip \
bash
RUN python3 -m pip install --no-cache-dir pipx --break-system-packages

RUN python3 -m pipx ensurepath --global
ADD . /restic-compose-backup
WORKDIR /restic-compose-backup
Expand Down
2 changes: 0 additions & 2 deletions src/crontab

This file was deleted.

2 changes: 1 addition & 1 deletion src/restic_compose_backup/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Config:
default_backup_command = "source /env.sh && rcb backup > /proc/1/fd/1"
default_crontab_schedule = "*/5 * * * *"
default_crontab_schedule = "0 2 * * *"

"""Bag for config values"""
def __init__(self, check=True):
Expand Down
3 changes: 2 additions & 1 deletion src/restic_compose_backup/cron.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from croniter import croniter
"""
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
Expand All @@ -20,7 +21,7 @@ def generate_crontab(config):
if schedule:
schedule = schedule.strip()
schedule = strip_quotes(schedule)
if not validate_schedule(schedule):
if not croniter.is_valid(schedule):
schedule = config.default_crontab_schedule
else:
schedule = config.default_crontab_schedule
Expand Down
1 change: 1 addition & 0 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
]),
install_requires=[
'docker~=7.1.0',
'croniter~=5.0.1'
],
entry_points={'console_scripts': [
'restic-compose-backup = restic_compose_backup.cli:main',
Expand Down
4 changes: 2 additions & 2 deletions start-live-system.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docker compose -p live-system -f docker-compose-backup-service.yaml -f docker-compose-live.yaml down -v
docker compose -p live-system -f docker-compose-backup-service.yaml -f docker-compose-live.yaml up --build --force-recreate -d
docker compose -p live -f docker-compose-backup-service.yaml -f docker-compose-live.yaml down -v
docker compose -p live -f docker-compose-backup-service.yaml -f docker-compose-live.yaml up --build --force-recreate -d
2 changes: 2 additions & 0 deletions start-live-two-with-restore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
docker compose -p live-two -f docker-compose-live-two.yaml -f docker-compose-restore-service.yaml down -v
docker compose -p live-two -f docker-compose-live-two.yaml -f docker-compose-restore-service.yaml up --build --force-recreate -d
1 change: 0 additions & 1 deletion stop-backup-system.sh

This file was deleted.

1 change: 1 addition & 0 deletions stop-live-two.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker compose -p restore-test -f docker-compose-live-two.yaml -f docker-compose-restore-service.yaml down
File renamed without changes.

0 comments on commit 7682500

Please sign in to comment.