Last active
April 14, 2020 18:02
-
-
Save vivirenremoto/1faa19d5eb494b605ad5f80988baab7e to your computer and use it in GitHub Desktop.
Backup files and databases to S3
This file contains 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
DB_HOST="localhost" | |
DB_USER="xxx" | |
DB_PASS="xxx" | |
BUCKET="xxx" | |
DIR="/home/xxx" | |
#zip database | |
for DB in $(mysql --host=$DB_HOST --user=$DB_USER --password=$DB_PASS -e 'show databases' -s --skip-column-names); do mysqldump --host=$DB_HOST --user=$DB_USER --password=$DB_PASS $DB | gzip -9 > $DIR/../BACKUPS/DB/$DB.sql.gz; done; | |
#zip files | |
cd $DIR; | |
for i in */; do zip -r "$DIR/../BACKUPS/WEBS/${i%/}.zip" "$i"; done; | |
#upload s3 | |
aws s3 mv $DIR/../BACKUPS s3://$BUCKET --recursive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment