From 35613ce009980d70dadc00250fc68188c873eb2a Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Fri, 28 May 2021 00:36:25 -0500 Subject: [PATCH] Put hostname in front for backup filename and pad number with zeros --- openwrt_backup/config.py | 4 ++-- openwrt_backup/utils.py | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/openwrt_backup/config.py b/openwrt_backup/config.py index b3f9aba..827e66c 100644 --- a/openwrt_backup/config.py +++ b/openwrt_backup/config.py @@ -18,8 +18,8 @@ CACHE_DIR = ensure_directory_exists(appdirs.user_cache_dir) CONFIG_FILE_PATH = CONFIG_DIR / "config.toml" PACKAGE_ROOT = Path(__file__).absolute().parent -HOSTNAME = 1 -NUMBER = 0 +HOSTNAME = 0 +NUMBER = 1 if not CONFIG_FILE_PATH.exists(): shutil.copy(PACKAGE_ROOT / "config.toml", CONFIG_FILE_PATH) diff --git a/openwrt_backup/utils.py b/openwrt_backup/utils.py index ed132d0..27dff4d 100755 --- a/openwrt_backup/utils.py +++ b/openwrt_backup/utils.py @@ -72,4 +72,7 @@ def get_next_number(backup_path: Path, hostname): def get_new_backup_filepath(backup_path: Path, time_format, hostname): next_number = get_next_number(backup_path, hostname) dt = datetime.datetime.today() - return backup_path / f"{next_number}__{hostname}__{dt.strftime(time_format)}.tar.gz" + return ( + backup_path + / f"{hostname}__{next_number:03d}__{dt.strftime(time_format)}.tar.gz" + )