Last active
March 9, 2022 14:17
-
-
Save j-dexx/1d660bdc57e8fc9c5520e980db2655d3 to your computer and use it in GitHub Desktop.
Back Ups To S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 1 * * * /var/www/automated_backups/site-backup.sh >/dev/null 2>&1 | |
0 5 * * * /var/www/automated_backups/sync-with-s3.sh >> /var/log/s3-backup.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SITE_NAME="" | |
BACK_UP_PATH="/var/www/automated_backups/sites" | |
CONTENT_BACK_UP_PATH="$BACK_UP_PATH/$SITE_NAME" | |
DATE=$(date +"%d-%b-%Y") | |
# Database credentials | |
USER="" | |
PASSWORD="" | |
HOST="" | |
DB_NAME="" | |
# Magento media folder location | |
MEDIA_FOLDER="" | |
cd $CONTENT_BACK_UP_PATH || exit 0 | |
# Set default file permissions | |
umask 177 | |
# Dump database into SQL file | |
mysqldump --user=$USER --password=$PASSWORD --host=$HOST $DB_NAME > $CONTENT_BACK_UP_PATH/$DB_NAME-$DATE.sql | |
# tar the media folder | |
ARCHIVE_NAME=media-$DATE.tar.gz | |
tar czvf $ARCHIVE_NAME $MEDIA_FOLDER/* | |
# Delete files older than 30 days | |
find $CONTENT_BACK_UP_PATH/* -mtime +7 -exec rm {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SITE_NAME="stackers" | |
BACK_UP_PATH="/var/www/automated_backups/sites" | |
CONTENT_BACK_UP_PATH="$BACK_UP_PATH/$SITE_NAME" | |
DATE=$(date +"%d-%b-%Y") | |
# Database credentials | |
USER="stackers" | |
PASSWORD="passw0rd323" | |
HOST="127.0.0.1" | |
DB_NAME="stackers_magento" | |
# Magento media folder location | |
MEDIA_FOLDER="/var/www/html/pub/media" | |
cd $CONTENT_BACK_UP_PATH || exit 0 | |
# Set default file permissions | |
umask 177 | |
# Dump database into SQL file | |
mysqldump --user=$USER --password=$PASSWORD --host=$HOST $DB_NAME > $CONTENT_BACK_UP_PATH/$DB_NAME-$DATE.sql | |
# tar the media folder | |
ARCHIVE_NAME=media-$DATE.tar.gz | |
tar czvf $ARCHIVE_NAME $MEDIA_FOLDER/* | |
# Delete files older than 30 days | |
find $CONTENT_BACK_UP_PATH/* -mtime +7 -exec rm {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# AWS Details | |
AWS_CLI="/root/.local/bin/aws" | |
BACK_UP_PATH="/var/www/automated_backups/sites" | |
BUCKET_NAME="stackers-backups-production" | |
# sync with S3 using the AWS CLI | |
$AWS_CLI s3 sync $BACK_UP_PATH s3://$BUCKET_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment