Create new script to run this python script from anywhere, and a setup script to add it to path.

This commit is contained in:
Craig
2025-04-23 16:44:45 +01:00
parent a1ba360331
commit 3871c3fc8f
4 changed files with 55 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Commands ## Commands
- Run the backup script: `python3 backup.py` - Run the backup script: `python3 backup.py`
- Install for system-wide access: `./setup.sh`
- No formal testing framework is used - No formal testing framework is used
## Code Style Guidelines ## Code Style Guidelines
@@ -18,6 +19,8 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Project Structure ## Project Structure
- `/configs/`: JSON configuration files for different backup jobs - `/configs/`: JSON configuration files for different backup jobs
- `backup.py`: Main script for creating tar.gz or zip archives of specified directories - `backup.py`: Main script for creating tar.gz or zip archives of specified directories
- `backup`: Shell script wrapper to run backup.py from any directory
- `setup.sh`: Installation script to make the backup command available system-wide
## Config File Format ## Config File Format
```json ```json

View File

@@ -10,6 +10,26 @@ Simple-Backup provides:
- Pattern-based file exclusion - Pattern-based file exclusion
- Cross-platform compatibility on Linux systems - Cross-platform compatibility on Linux systems
## Installation
You can install Simple-Backup system-wide to run it from anywhere:
```bash
# Clone the repository
git clone https://github.com/yourusername/simple-backup.git
cd simple-backup
# Run the setup script
./setup.sh
```
The setup script will either:
1. Create a symlink in `/usr/local/bin` if you have write permissions
2. Prompt you to run with sudo if needed
3. Offer to add the directory to your PATH in ~/.bashrc
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: Create new backup jobs by adding JSON configuration files to the `configs/` directory. Each configuration file should include:
@@ -45,10 +65,10 @@ You can run backups manually or as a scheduled task:
### Manual Execution ### Manual Execution
```bash ```bash
# Make the script executable if needed # Once installed, simply run:
chmod +x backup.py backup
# Run the backup # Or from the repository directory:
./backup.py ./backup.py
``` ```

2
backup Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
cd "$(dirname "$(realpath "$0")")" && python3 backup.py

27
setup.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
# Create executable backup script
chmod +x backup.py
chmod +x backup
# Create a symlink in /usr/local/bin to make it accessible from anywhere
if [ -w /usr/local/bin ]; then
# If we have write permission to /usr/local/bin
ln -sf "$(realpath backup)" /usr/local/bin/backup
echo "Created symlink in /usr/local/bin/backup"
else
# If we don't have permission, suggest using sudo
echo "To install system-wide, run:"
echo "sudo ln -sf $(realpath backup) /usr/local/bin/backup"
# Offer to add to user's path as an alternative
read -p "Would you like to add it to your PATH in ~/.bashrc instead? (y/n) " choice
if [[ $choice == "y" || $choice == "Y" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "export PATH=\"\$PATH:$SCRIPT_DIR\"" >> ~/.bashrc
echo "Added to PATH in ~/.bashrc"
echo "Run 'source ~/.bashrc' to apply changes"
fi
fi
echo "Setup complete. You can now run 'backup' from anywhere."