|
|
|
@ -1,4 +1,29 @@ |
|
|
|
from argparse import ArgumentParser |
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
from openwrt_backup.retrieve import make_backup_on_remote, retrieve_backup_on_remote |
|
|
|
from openwrt_backup.utils import ( |
|
|
|
client_from_config, |
|
|
|
exec_remote, |
|
|
|
get_new_backup_filepath, |
|
|
|
) |
|
|
|
from openwrt_backup.config import CONFIG_DATA |
|
|
|
|
|
|
|
|
|
|
|
def do_backup( |
|
|
|
config_hostname, |
|
|
|
ssh_config_root: Path, |
|
|
|
backup_path: Path, |
|
|
|
tmp_path: Path, |
|
|
|
time_format, |
|
|
|
dry, |
|
|
|
): |
|
|
|
client = client_from_config(config_hostname, ssh_config_root) |
|
|
|
stdout, stderr = exec_remote(client, "echo $HOSTNAME") |
|
|
|
hostname = stdout.read().decode().rstrip() |
|
|
|
dest = get_new_backup_filepath(backup_path, time_format, hostname) |
|
|
|
backup_on_remote = make_backup_on_remote(client, tmp_path) |
|
|
|
retrieve_backup_on_remote(client, backup_on_remote, dest) |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
@ -12,3 +37,11 @@ def main(): |
|
|
|
"name", help="hostname in ssh_config file for openwrt device we need to backup" |
|
|
|
) |
|
|
|
args = parser.parse_args() |
|
|
|
do_backup( |
|
|
|
args.name, |
|
|
|
Path(CONFIG_DATA["ssh"]["root"]).expanduser(), |
|
|
|
Path(CONFIG_DATA["backup"]["path"]).expanduser(), |
|
|
|
Path(CONFIG_DATA["router"]["temp"]), |
|
|
|
CONFIG_DATA["backup"]["time_format"], |
|
|
|
args.dry, |
|
|
|
) |