This project was proposed in the DevOps Path from roadmap.sh, with the objective of creating a tool to compress logs in a given directory, copy the tar.gz file to a bucket S3 and clean the directory, for archiving purposes.
Verify if AWS-CLI is installed on your Linux terminal by running:
aws --versionNote: If AWS-CLI is not installed, refer to the Installing or updating to the latest version of the AWS CLI (AWS) documentation
To use the tool, first you need to authenticate with AWS using the command:
aws loginNext, export the S3 bucket URL (s3:// + Bucket name) as an environment variable named S3_BUCKET, as shown below:
export S3_BUCKET="s3://bucket_name"Then you can run the command below to execute the script using sudo -E for the required permissions and to preserve the AWS session from the previous step:
sudo -E ./log-archive.sh /path/file