Installing AWS CLI

The AWS CLI packages are available under the default repositories on most of the Linux systems. You can install it by running one of the following commands: You can also another article to install latest AWS CLI on any Linux system. Once the installation finished, check the awscli version by executing:

Create A Shell Script

Now, create a shell script file on your system and add the below content. For this tutorial, I created file using: and added the following content:

Make sure to update S3_BUCKET_NAME and DIR_TO_BACKUP in the script. You can also change the backup file name in BACKUP_FILENAME variable. Save file and close it. Now, you have a shell script to backup website content to s3 buckets.

Running Shell Script

Make the shell script executable by running the following command. Now, you can test the script by executing it manually. On successful, backups will be uploaded to s3 bucket. Which you can view using aws s3 ls command.

Schedule Script in Cron

Next, schedule your script to crontab to automate this job. To edit the crontab of current user, type: Add the following entry to the crontab: Save file and close the editor.

Wrap Up

This tutorial provides you a shell script to backup website content to the S3 bucket. Also includes the instruction to run this script.