Add backup command

This commit is contained in:
2021-12-13 22:38:40 +01:00
parent f1c862e1d1
commit 6cbbce030c

View File

@ -1,4 +1,7 @@
import os
import time
from contextlib import closing from contextlib import closing
from shutil import copyfile
import typer import typer
from dhooks import Webhook from dhooks import Webhook
@ -89,5 +92,22 @@ def check() -> None:
hook.send(f":robot: :mega: {entry.title}") hook.send(f":robot: :mega: {entry.title}")
@app.command()
def backup() -> None:
"""Backup the database"""
backup_dir = os.path.join(Settings.data_dir, "backup")
os.makedirs(backup_dir, exist_ok=True)
# Get the current time
current_time = time.strftime("%Y-%m-%d_%H-%M-%S")
backup_file_location = os.path.join(
Settings.data_dir, "backup", f"db_{current_time}.sqlite"
)
copyfile(Settings.db_file, backup_file_location)
typer.echo(f"{Settings.db_file} backed up to {backup_dir}")
if __name__ == "__main__": if __name__ == "__main__":
app() app()