|
|
|
@ -0,0 +1,31 @@ |
|
|
|
from argparse import ArgumentParser |
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
from tibi_hardlinks.config import CONFIG_DATA |
|
|
|
from tibi_hardlinks.backups import Backup, create_backup_directory_name |
|
|
|
|
|
|
|
|
|
|
|
def find_all_property_files(): |
|
|
|
for path in map(Path, CONFIG_DATA["input"]["backup_paths"]): |
|
|
|
if path.exists(): |
|
|
|
yield from path.absolute().glob("*.properties") |
|
|
|
|
|
|
|
|
|
|
|
def hardlink_all_files(files, dry=False): |
|
|
|
for prop_file in files: |
|
|
|
backup = Backup(prop_file) |
|
|
|
dest_dir = create_backup_directory_name( |
|
|
|
backup.backup_info, CONFIG_DATA["customization"]["time_format"] |
|
|
|
) |
|
|
|
if dry: |
|
|
|
print(f"mkdir: {dest_dir}") |
|
|
|
else: |
|
|
|
dest_dir.mkdir(parents=True, exist_ok=True) |
|
|
|
backup.hardlink_to(dest_dir, dry) |
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
parser = ArgumentParser() |
|
|
|
parser.add_argument("-d", "--dry", action="store_true", help="Don't do anything") |
|
|
|
args = parser.parse_args() |
|
|
|
hardlink_all_files(find_all_property_files(), args.dry) |