Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 79 additions & 1 deletion src/ocbs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,83 @@ def checkpoint(ctx, reason, serve):
sys.exit(1)


@main.command()
@click.option('--scope', type=click.Choice(['config', 'config+session', 'config+session+workspace']),
default='config', help='Backup scope')
@click.option('--verify', is_flag=True, help='Verify archive after creation')
@click.option('--output', '-o', type=click.Path(exists=False, file_okay=False, dir_okay=True),
help='Output directory for the archive')
def native_backup(scope, verify, output):
"""Run OpenClaw native backup to create a tar.gz archive."""
import subprocess

args = ["openclaw", "backup", "create"]

if scope == "config":
args.append("--only-config")
elif scope == "config+session":
args.append("--no-include-workspace")
# Full scope uses no flags

if verify:
args.append("--verify")

if output:
args.extend(["--output", output])

try:
result = subprocess.run(
args,
capture_output=True,
text=True,
timeout=600
)

if result.returncode != 0:
click.echo(f"Native backup failed: {result.stderr}", err=True)
sys.exit(1)

click.echo(f"Native backup created successfully:\n{result.stdout}")
except subprocess.TimeoutExpired:
click.echo("Error: Native backup timed out (10 minutes)", err=True)
sys.exit(1)
except FileNotFoundError:
click.echo("Error: openclaw command not found. Ensure OpenClaw is installed.", err=True)
sys.exit(1)
except Exception as e:
click.echo(f"Error running native backup: {e}", err=True)
sys.exit(1)


@main.command()
@click.argument('archive', type=click.Path(exists=True))
def native_verify(archive):
"""Verify a native backup archive."""
import subprocess

try:
result = subprocess.run(
["openclaw", "backup", "verify", archive],
capture_output=True,
text=True,
timeout=60
)

if result.returncode != 0:
click.echo(f"Verification failed: {result.stderr}", err=True)
sys.exit(1)

click.echo(f"Archive verified successfully:\n{result.stdout}")
except subprocess.TimeoutExpired:
click.echo("Error: Verification timed out", err=True)
sys.exit(1)
except FileNotFoundError:
click.echo("Error: openclaw command not found. Ensure OpenClaw is installed.", err=True)
sys.exit(1)
except Exception as e:
click.echo(f"Error verifying archive: {e}", err=True)
sys.exit(1)


if __name__ == '__main__':
main()
main()
2 changes: 1 addition & 1 deletion src/ocbs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,4 +913,4 @@ def get_checkpoint_serves(self, checkpoint_id: str) -> list[dict]:
'restored': bool(row[6])
}
for row in cursor.fetchall()
]
]
2 changes: 1 addition & 1 deletion src/ocbs/skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,4 @@ async def native_verify(self, archive: str) -> str:
}
}
}
}
}