feat: replace --start/--end with --days param on backup command
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from datetime import timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
@@ -31,11 +31,14 @@ def scan(ctx, count):
|
||||
|
||||
|
||||
@main.command()
|
||||
@click.option("--start", required=True, type=click.DateTime(formats=["%Y-%m-%d"]), help="Start date (UTC, inclusive)")
|
||||
@click.option("--end", required=True, type=click.DateTime(formats=["%Y-%m-%d"]), help="End date (UTC, exclusive)")
|
||||
@click.option("--days", required=True, type=int, help="Backup orders older than N days (min 1)")
|
||||
@click.option("--scan", "scan_path", default=None, type=click.Path(), help="Path to scan CSV (default: latest in scan_dir)")
|
||||
@click.pass_context
|
||||
def backup(ctx, start, end, scan_path):
|
||||
def backup(ctx, days, scan_path):
|
||||
if days < 1:
|
||||
click.echo("Error: --days must be at least 1")
|
||||
raise SystemExit(1)
|
||||
|
||||
cfg = load_config(ctx.obj["config_path"])
|
||||
from order_bak.backup import backup_orders
|
||||
|
||||
@@ -48,18 +51,14 @@ def backup(ctx, start, end, scan_path):
|
||||
raise SystemExit(1)
|
||||
scan_file = scan_files[-1]
|
||||
|
||||
start_utc = start.replace(tzinfo=timezone.utc)
|
||||
end_utc = end.replace(tzinfo=timezone.utc)
|
||||
|
||||
if start_utc >= end_utc:
|
||||
click.echo("Error: --start must be before --end")
|
||||
raise SystemExit(1)
|
||||
today_utc = datetime.now(timezone.utc).replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
cutoff = today_utc - timedelta(days=days)
|
||||
|
||||
click.echo(f"Backing up orders before {cutoff.strftime('%Y-%m-%d')} UTC")
|
||||
backup_orders(
|
||||
scan_path=scan_file,
|
||||
backup_dir=Path("./backups"),
|
||||
start=start_utc,
|
||||
end=end_utc,
|
||||
cutoff=cutoff,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user