Backup sensitive files to S3 bucket everyday

Start

#!/bin/bash

# Set variables
AWS_ACCESS_KEY_ID=<Your AWS access key>
AWS_SECRET_ACCESS_KEY=<Your AWS secret key>
S3_BUCKET=<Your S3 bucket name>

# Backup files
TIMESTAMP=$(date +%Y.%m.%d_%H.%M.%S)

# Sync files with S3 bucket
aws s3 sync . s3://$S3_BUCKET/backup_$TIMESTAMP --exclude "*" --include "*.conf" --include ".secret" --access_key $AWS_ACCESS_KEY_ID --secret_key $AWS_SECRET_ACCESS_KEY

# Run script every day
0 0 * * * /root/backup_files.sh
Previous Story

This script automatically installs updates to the OS every night

Next Story

GitHub code-signing certificates stolen (but will be revoked this week)