Skip to content

Commit

Permalink
GH-147: Remove colon character from backup filename
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-anderson-bsl committed Aug 9, 2021
1 parent d9810ee commit e02e891
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The changelog is applicable from version `1.0.0` onwards.

- [#118](https://github.com/brightsparklabs/appcli/issues/118) Added `version` command to fetch version of app managed by appcli.
- [#144](https://github.com/brightsparklabs/appcli/issues/144) Added `--lines/-n` option to the `logs` commands for orchestrators. This is the `n` number of lines from the end to start the tail.
- [#147](https://github.com/brightsparklabs/appcli/issues/147) Remove ':' character from backup filenames, to allow tools like `tar` to work with the unmodified filename.

---

Expand Down
9 changes: 6 additions & 3 deletions appcli/backup_manager/backup_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,13 @@ def __create_backup_filename(self, app_name: str, backup_name: str) -> str:
Returns:
The formatted .tgz filename.
"""
now: datetime = datetime.datetime.now(datetime.timezone.utc).replace(
microsecond=0
now: str = (
datetime.datetime.now(datetime.timezone.utc)
.replace(microsecond=0)
.isoformat()
.replace(":", "")
)
return f"{app_name.upper()}_{backup_name.upper()}_{now.isoformat()}.tgz"
return f"{app_name.upper()}_{backup_name.upper()}_{now}.tgz"

def __rolling_backup_deletion(self, backup_dir: Path):
"""Delete old backups, will only keep the most recent backups.
Expand Down
40 changes: 20 additions & 20 deletions tests/test_backup_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ def test_backup_with_limit_keep_last_5(
}
expected_result = set(
{
"TEST_APP_FULL_2020-12-25T17:06:00.tgz",
"TEST_APP_FULL_2020-12-25T17:06:01.tgz",
"TEST_APP_FULL_2020-12-25T17:06:02.tgz",
"TEST_APP_FULL_2020-12-25T17:06:03.tgz",
"TEST_APP_FULL_2020-12-25T17:06:04.tgz",
"TEST_APP_FULL_2020-12-25T170600.tgz",
"TEST_APP_FULL_2020-12-25T170601.tgz",
"TEST_APP_FULL_2020-12-25T170602.tgz",
"TEST_APP_FULL_2020-12-25T170603.tgz",
"TEST_APP_FULL_2020-12-25T170604.tgz",
}
)

Expand Down Expand Up @@ -361,7 +361,7 @@ def test_backup_with_unsafe_name_for_files(
"name": "Backup: Weekly > Sunday",
}
expected_result = [
"TEST_APP_BACKUP-WEEKLY-SUNDAY_2020-12-25T17:05:55.tgz",
"TEST_APP_BACKUP-WEEKLY-SUNDAY_2020-12-25T170555.tgz",
]

backup_config = BackupConfig.from_dict(conf)
Expand Down Expand Up @@ -912,7 +912,7 @@ def test_restore_triggers_config_backups(
backup_tgz,
tmp_path,
):
expected_result = set({"TEST_APP_FULL_2020-12-25T17:05:55.tgz"})
expected_result = set({"TEST_APP_FULL_2020-12-25T170555.tgz"})
# Set the backup directory.
backup_dir = tmp_path / BASE_BACKUP_DIR
# Create the temporary conf directory to restore into.
Expand Down Expand Up @@ -989,7 +989,7 @@ def test_view_backups(
tmp_path,
capsys,
):
expected = "full/TEST_APP_FULL_2020-12-25T17:05:55.tgz\n"
expected = "full/TEST_APP_FULL_2020-12-25T170555.tgz\n"
# Set the backup directory.
backup_dir = tmp_path / BASE_BACKUP_DIR
# Create the click context that backup_manager expects to deal with
Expand Down Expand Up @@ -1024,16 +1024,16 @@ def test_view_multiple_backups_descending_order(
capsys,
):
expected = (
"full/TEST_APP_FULL_2020-12-25T17:06:04.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:06:03.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:06:02.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:06:01.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:06:00.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:05:59.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:05:58.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:05:57.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:05:56.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T17:05:55.tgz\n"
"full/TEST_APP_FULL_2020-12-25T170604.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170603.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170602.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170601.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170600.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170559.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170558.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170557.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170556.tgz\n"
+ "full/TEST_APP_FULL_2020-12-25T170555.tgz\n"
)
# Set the backup directory.
backup_dir = tmp_path / BASE_BACKUP_DIR
Expand Down Expand Up @@ -1071,8 +1071,8 @@ def test_view_backups_multiple_backup_strategies(
capsys,
):
expected = (
"logs/TEST_APP_LOGS_2020-12-25T17:05:56.tgz\n"
"full/TEST_APP_FULL_2020-12-25T17:05:55.tgz\n"
"logs/TEST_APP_LOGS_2020-12-25T170556.tgz\n"
"full/TEST_APP_FULL_2020-12-25T170555.tgz\n"
)
# Set the backup directory.
backup_dir = tmp_path / BASE_BACKUP_DIR
Expand Down

0 comments on commit e02e891

Please sign in to comment.