|
|
|
@ -1,3 +1,4 @@ |
|
|
|
import datetime |
|
|
|
from pathlib import Path |
|
|
|
from subprocess import list2cmdline |
|
|
|
from typing import Union |
|
|
|
@ -52,3 +53,21 @@ def exec_remote(client: paramiko.SSHClient, command: Union[str, list]): |
|
|
|
command = list2cmdline(command) |
|
|
|
stdin, stdout, stderr = client.exec_command(command) |
|
|
|
return stdout, stderr |
|
|
|
|
|
|
|
|
|
|
|
def get_next_number(backup_path: Path, hostname): |
|
|
|
f_names = (path.name for path in backup_path.glob("*.tar.gz")) |
|
|
|
f_names_fields = map(lambda s: s.split("__"), f_names) |
|
|
|
f_names_fields_filtered = filter( |
|
|
|
lambda fields: fields[1] == hostname, f_names_fields |
|
|
|
) |
|
|
|
try: |
|
|
|
return max(int(fields[0]) for fields in f_names_fields_filtered) + 1 |
|
|
|
except ValueError: |
|
|
|
return 0 |
|
|
|
|
|
|
|
|
|
|
|
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" |