diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c79ff4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 backup_scripts + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..500966c --- /dev/null +++ b/README.md @@ -0,0 +1,142 @@ +# Backup Scripts + +A collection of shell scripts for creating and restoring backups of disks, directories, and folders on Linux systems. + +## Overview + +This repository contains three backup utilities: + +- **`backup`** - Universal backup tool that handles both disks and directories +- **`backup_disk`** - Specialized tool for disk/partition backups +- **`backup_folder`** - Specialized tool for directory backups using SquashFS + +## Requirements + +- Linux operating system +- Root privileges (all scripts require sudo/root access) +- Basic utilities: `dd`, `gzip` +- Optional: `mksquashfs`/`unsquashfs` for SquashFS compression +- Optional: `tar` as fallback for directory backups + +## Installation + +1. Clone or download the scripts to your system +2. Make the scripts executable: + ```bash + chmod +x backup backup_disk backup_folder + ``` +3. Optionally, move them to a directory in your PATH (e.g., `/usr/local/bin/`) + +## Usage + +### Universal Backup Tool (`backup`) + +The main backup script that can handle both disks and directories automatically. + +#### Create Backup +```bash +sudo ./backup --create --disk /dev/sda --file backup.img.gz +sudo ./backup --create --directory /home/user --file home_backup.sqsh +``` + +#### Restore Backup +```bash +sudo ./backup --restore --file backup.img.gz --disk /dev/sda +sudo ./backup --restore --file home_backup.sqsh --directory /home/user +``` + +#### Options +- `-c, --create` - Create a backup +- `-r, --restore` - Restore from backup +- `-d, --disk, --directory ` - Source disk or directory +- `-f, --file, --filename ` - Backup file path +- `-h, --help` - Show help message + +### Disk Backup Tool (`backup_disk`) + +Specialized tool for creating compressed disk images using dd and gzip. + +#### Create Disk Backup +```bash +sudo ./backup_disk create /dev/sda disk_backup.img.gz +``` + +#### Restore Disk Backup +```bash +sudo ./backup_disk restore disk_backup.img.gz /dev/sda +``` + +### Folder Backup Tool (`backup_folder`) + +Specialized tool for creating compressed directory backups using SquashFS. + +#### Create Folder Backup +```bash +sudo ./backup_folder create /home/user folder_backup.sqsh +``` + +#### Restore Folder Backup +```bash +sudo ./backup_folder restore folder_backup.sqsh /home/user +``` + +## Features + +- **Smart Detection**: The universal `backup` script automatically detects whether the source is a disk or directory +- **Multiple Compression Methods**: + - SquashFS for directories (preferred) + - tar as fallback for directories + - gzip compression for disk images +- **Progress Monitoring**: Shows progress during disk operations +- **Error Handling**: Validates inputs and provides helpful error messages +- **Flexible Usage**: Multiple command-line argument formats supported + +## Safety Considerations + +⚠️ **WARNING**: These scripts perform low-level disk operations and can cause data loss if used incorrectly. + +- Always verify disk paths before running restore operations +- Test backups in a safe environment first +- Ensure you have sufficient disk space for backups +- Double-check source and destination paths +- Consider using `--dry-run` options when available + +## Examples + +### Complete System Backup +```bash +# Backup entire disk +sudo ./backup_disk create /dev/sda system_backup.img.gz + +# Backup home directory +sudo ./backup_folder create /home home_backup.sqsh +``` + +### Selective Restore +```bash +# Restore only home directory +sudo ./backup_folder restore home_backup.sqsh /home + +# Restore full system (be very careful!) +sudo ./backup_disk restore system_backup.img.gz /dev/sda +``` + +## File Formats + +- **Disk backups**: Compressed with gzip (`.img.gz`) +- **Directory backups**: SquashFS format (`.sqsh`) or tar archives (`.tar`) + +## Troubleshooting + +- **Permission denied**: Ensure you're running with root privileges +- **Command not found**: Install missing dependencies (`squashfs-tools` for SquashFS support) +- **No space left**: Check available disk space before creating backups +- **Invalid device**: Verify disk paths with `lsblk` or `fdisk -l` + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## Contributing + +Feel free to submit issues, feature requests, or pull requests to improve these backup scripts. \ No newline at end of file