This project provides two Bash scripts to facilitate backing up and restoring data using AWS S3 Glacier storage. These scripts streamline the process of archiving, hashing, uploading, and retrieving backups while ensuring data integrity through hash verification.
- Syncs specified directories to a temporary location using
rsync
. - Creates an uncompressed tarball of the data for efficient storage.
- Computes a SHA256 hash of the tarball to ensure data integrity.
- Uploads the tarball and its corresponding hash to an AWS S3 bucket.
- Downloads a backup tarball and its hash from an AWS S3 bucket.
- Verifies the integrity of the downloaded tarball using the hash.
- Extracts the tarball to a specified directory after successful verification.
- AWS CLI configured with appropriate permissions to access the target S3 bucket.
- Required system tools:
rsync
tar
sha256sum
- An AWS S3 bucket configured to use Glacier storage class for cost-effective long-term archiving.
-
Configure the following variables in
glacier_backup.sh
:DATA_DIR
: The directory to back up.TEMP_DIR
: The temporary location to stage the data.BUCKET
: The name of the target S3 bucket.
-
Run the script:
./glacier_backup.sh
-
The script will:
- Sync data to the temporary directory.
- Create a tarball of the synced data.
- Compute and save a hash for the tarball.
- Upload the tarball and hash to the S3 bucket.
- Clean up local files and temporary directories.
-
Configure the following variables in
glacier_pull.sh
:BUCKET
: The name of the S3 bucket.DATE_TO_RETRIEVE
: The date of the backup to retrieve (e.g.,2023-10-05
).TARGET_DIR
: The directory where the backup will be restored.
-
Run the script:
./glacier_pull.sh
-
The script will:
- Download the tarball and its hash from the S3 bucket.
- Verify the integrity of the tarball using the hash.
- Extract the tarball to the target directory.
Suppose you want to back up /home/data
to an S3 bucket named my-backup-bucket
:
- Set
DATA_DIR
to/home/data
,TEMP_DIR
to/tmp/data-backup
, andBUCKET
tomy-backup-bucket
. - Run the script:
./glacier_backup.sh
To restore a backup from 2023-10-05
to /home/restore
:
- Set
BUCKET
tomy-backup-bucket
,DATE_TO_RETRIEVE
to2023-10-05
, andTARGET_DIR
to/home/restore
. - Run the script:
./glacier_pull.sh
- Ensure your AWS credentials are securely configured using environment variables or AWS IAM roles.
- The tarball and its hash are temporarily stored on disk during the backup and restore processes. Use secure directories for temporary storage.
- Delete temporary files promptly to minimize exposure.
Contributions are welcome to improve these scripts! Please fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.
These scripts are provided as-is without warranty of any kind. Use them at your own risk and ensure compliance with your organization's backup policies.