backup: Add backup-cli tool and use it to initialize the backups

This commit is contained in:
Christian Decker
2020-04-04 14:25:33 +02:00
parent c049069cff
commit 4e19c32444
4 changed files with 86 additions and 34 deletions

39
backup/backup-cli Executable file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python3
from backup import FileBackend
import os
import click
import json
@click.command()
@click.argument("lightning-dir", type=click.Path(exists=True))
@click.argument("backup-dir", type=click.Path(exists=True))
def init(lightning_dir, backup_dir):
destination = 'file://' + os.path.join(backup_dir, 'backup.dbak')
backend = FileBackend(destination)
backend.version, backend.prev_version = 0, 0
backend.offsets = [512, 0]
backend.version_count = 0
backend.write_metadata()
lock_file = os.path.join(lightning_dir, "backup.lock")
with open(lock_file, "w") as f:
f.write(json.dumps({
'backend_url': destination,
}))
print("Initialized backup backend {destination}, you can now start c-lightning".format(
destination=destination,
))
@click.group()
def cli():
pass
cli.add_command(init)
if __name__ == "__main__":
cli()