Skip to content

Instantly share code, notes, and snippets.

@ericmil87
Created February 24, 2022 05:35
Show Gist options
  • Save ericmil87/a6460652c7976b852b21bb31e38123e8 to your computer and use it in GitHub Desktop.
Save ericmil87/a6460652c7976b852b21bb31e38123e8 to your computer and use it in GitHub Desktop.
# Shell Script to do a REAL BACKUP on Vestacp and MySQL and then send to AWS S3 storage.
# >>>> Must have awscli installed and configured <<<<
# YOU NEED TO EDIT this file only in the aws upload part and change to your correct s3 backup bucket path example: s3://PUT-YOUR-S3-BUCKET-TO-BACKUP/
# Created by Eric Milfont on 24-02-2022
# IG: @ericmilfont
#create sql file for each db
echo "Backup sql databases"
for DB in $(mysql -e 'show databases' -s --skip-column-names); do
mysqldump $DB > "$DB.sql";
done
# zip sql files
echo "Backup zipping sql files"
zip mysqlbkp.zip *.sql
#remove sql files
echo "Backup removing sql files cuz we dont need anymore"
rm -f *.sql
#moving mysqlzip file to backup folder
echo "Backup moving sql zip file to backup folder"
mv mysqlbkp.zip /backup/mysqlbkp.zip
#begin zip vestacp and home files
echo "Backup zipping files"
zip -r -FS /backup/vesta.zip /vesta/
zip -r -y -FS /backup/home.zip /home/ -x "/home/admin/tmp/*"
echo "Backup uploading"
#upload to s3
aws s3 cp /backup/ s3://MY-S3-BUCKET-TO-BACKUP/$(date +%Y)/$(date +%Y%m%d)/ --recursive --exclude "/backup/.etc/*"
echo "Backup complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment