Allow creation of machine specific configs.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1 +1,5 @@
|
|||||||
.env
|
.env
|
||||||
|
|
||||||
|
# Configuration files except example
|
||||||
|
configs/*
|
||||||
|
!configs/example-config.json
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -32,7 +32,20 @@ After installation, you can run the `backup` command from any directory.
|
|||||||
|
|
||||||
## Configuration
|
## 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 |
|
| Field | Description |
|
||||||
|-------|-------------|
|
|-------|-------------|
|
||||||
@@ -74,6 +87,8 @@ backup
|
|||||||
./backup.py
|
./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)
|
### Scheduled Execution (Linux)
|
||||||
|
|
||||||
Add a cron job to run backups automatically, for example weekly on Saturday at 1:05 AM:
|
Add a cron job to run backups automatically, for example weekly on Saturday at 1:05 AM:
|
||||||
|
|||||||
14
backup.py
14
backup.py
@@ -146,9 +146,19 @@ def local_backup(output_dir: Path, backup_name: str, inputs: list, ignore_patter
|
|||||||
|
|
||||||
def backup_all():
|
def backup_all():
|
||||||
config_dir = Path(__file__).parent / "configs"
|
config_dir = Path(__file__).parent / "configs"
|
||||||
config_files = sorted(config_dir.glob("*"))
|
# Get all JSON files except the example config
|
||||||
print(config_files)
|
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:
|
for file in config_files:
|
||||||
|
print(f"\nProcessing backup configuration: {file.name}")
|
||||||
text = file.read_text()
|
text = file.read_text()
|
||||||
config = json.loads(text)
|
config = json.loads(text)
|
||||||
output_dir = Path(config["outputDir"]).expanduser().resolve()
|
output_dir = Path(config["outputDir"]).expanduser().resolve()
|
||||||
|
|||||||
Reference in New Issue
Block a user