From 677e846b24ac4aaac4bb3e15473b3a370e7081d1 Mon Sep 17 00:00:00 2001 From: Craig Date: Thu, 24 Apr 2025 16:54:51 +0100 Subject: [PATCH] Allow creation of machine specific configs. --- .gitignore | 4 ++++ README.md | 17 ++++++++++++++++- backup.py | 14 ++++++++++++-- configs/{personal.json => example-config.json} | 0 4 files changed, 32 insertions(+), 3 deletions(-) rename configs/{personal.json => example-config.json} (100%) diff --git a/.gitignore b/.gitignore index 4c49bd7..2fd0074 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .env + +# Configuration files except example +configs/* +!configs/example-config.json diff --git a/README.md b/README.md index 6beb004..9171eb1 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,20 @@ After installation, you can run the `backup` command from any directory. ## Configuration -Create new backup jobs by adding JSON configuration files to the `configs/` directory. Each configuration file should include: +The `configs/` directory contains JSON configuration files for your backup jobs. The repository includes an example config file (`example-config.json`) that you can use as a template. + +> **Important:** All config files except `example-config.json` are ignored by git. This allows you to have different configurations on different machines without affecting other installations. + +To get started, copy the example file to create your own configuration: +```bash +# Copy example to create your own config +cp configs/example-config.json configs/my-backup.json + +# Edit your new config file with your favorite editor +nano configs/my-backup.json +``` + +Each configuration file should include: | Field | Description | |-------|-------------| @@ -74,6 +87,8 @@ backup ./backup.py ``` +When executed, the script will process all JSON files in the `configs/` directory (except the example file), creating backups as specified in each configuration. If no valid config files are found, it will provide instructions for creating one. + ### Scheduled Execution (Linux) Add a cron job to run backups automatically, for example weekly on Saturday at 1:05 AM: diff --git a/backup.py b/backup.py index 83fd849..e0a70a2 100755 --- a/backup.py +++ b/backup.py @@ -146,9 +146,19 @@ def local_backup(output_dir: Path, backup_name: str, inputs: list, ignore_patter def backup_all(): config_dir = Path(__file__).parent / "configs" - config_files = sorted(config_dir.glob("*")) - print(config_files) + # Get all JSON files except the example config + config_files = sorted([f for f in config_dir.glob("*.json") if f.name != "example-config.json"]) + + if not config_files: + print("No configuration files found. Please create a config file in the 'configs' directory.") + print("You can copy the example-config.json to create your own configuration:") + print("cp configs/example-config.json configs/my-backup.json") + return + + print(f"Found {len(config_files)} config files: {[f.name for f in config_files]}") + for file in config_files: + print(f"\nProcessing backup configuration: {file.name}") text = file.read_text() config = json.loads(text) output_dir = Path(config["outputDir"]).expanduser().resolve() diff --git a/configs/personal.json b/configs/example-config.json similarity index 100% rename from configs/personal.json rename to configs/example-config.json