This script facilitates backups to a tape device. It supports full backups, incremental backups, and dry-run operations for testing without writing to the tape. Logs and snapshots are maintained to track operations and incremental backups.
tape_backup.sh <folder_to_backup> <mode> [tape_device]<folder_to_backup>: Mandatory. The folder to back up.<mode>: Mandatory. Specifies the type of backup:full: Perform a full backup.inc: Perform an incremental backup (uses snapshots).dry: Perform a dry run (testing without writing to the tape).
[tape_device]: Optional. The tape device to use. Defaults to/dev/st0.
- Full backup:
tape_backup.sh /path/to/folder full
- Incremental backup to a specific tape device:
tape_backup.sh /path/to/folder inc /dev/nst0
- Dry run:
tape_backup.sh /path/to/folder dry
- Logs: Stored in
tape_backup_logswithin the script's directory. - Snapshots: Stored in
tape_backup_snapshotswithin the script's directory.
DEFAULT_TAPE_DEVICE: Default tape device (/dev/st0).SCRIPT_DIR: Directory of the script.LOG_DIR: Directory for log files.SNAPSHOT_DIR: Directory for snapshot files.DATE: Current date and time for unique log file naming.
-
Argument Validation:
- Ensures the required folder exists and validates the mode parameter.
- Provides usage instructions if parameters are missing or invalid.
-
Mode-Based Operations:
- Full Backup (
full):- Backs up the specified folder to the tape device.
- Removes any existing snapshot file.
- Incremental Backup (
inc):- Performs a backup that only includes changes since the last backup using a snapshot file.
- Dry Run (
dry):- Simulates a backup without writing to the tape, using
/dev/null.
- Simulates a backup without writing to the tape, using
- Full Backup (
-
Error Handling:
- Logs errors and exits with a failure status if any issues occur during execution.
-
Logging:
- All operations are logged in
tape_backup_logs/backup_<date>.log.
- All operations are logged in
0: Success.1: Failure due to invalid arguments or backup errors.
- Log Directory:
tape_backup_logs - Snapshot Directory:
tape_backup_snapshots - Log File:
backup_<date>.log(e.g.,backup_2025-01-22_16-30-45.log) - Snapshot File:
<folder_name>_snapshot.snar
- Incremental backups require a snapshot file to track changes. This file is automatically managed by the script.
- Ensure the specified tape device is correctly connected and configured before running the script.
- Backup Failed:
- Check the log file for detailed error messages.
- Verify the tape device is operational and accessible.
- Invalid Folder:
- Confirm the folder path exists and is accessible.
Jaronchai Dilokkalayakul 2025 Tohoku University, Information Biology Lab