Skip to content

Instantly share code, notes, and snippets.

@kitzberger
Last active February 15, 2023 15:30
Show Gist options
  • Save kitzberger/2b0e12d75a9fa252a45bb198e9bf0252 to your computer and use it in GitHub Desktop.
Save kitzberger/2b0e12d75a9fa252a45bb198e9bf0252 to your computer and use it in GitHub Desktop.
#!/bin/bash
DB='xxx'
DB_GROUP=''
WEBROOT='/var/www/vhosts/xxx/html'
FOLDERS=( 'fileadmin' 'uploads' )
read -p "Backup DB? (y/N) " BACKUP_DB
if [ "$BACKUP_DB" == "y" ]; then
TABLES=`mysql --defaults-group-suffix=$DB_GROUP -BN $DB -e "show tables" | egrep -v '(cf_|cache|sys_log|sys_history|sys_refindex|tx_devlog|tx_solr_|tx_realurl_errorlog|zzz_deleted_|TABLE)' | xargs`
TABLES_NODATA=`mysql --defaults-group-suffix=$DB_GROUP -BN $DB -e "show tables" | egrep '(cf_|cache|sys_log|sys_history|sys_refindex|tx_devlog|tx_solr_|tx_realurl_errorlog|zzz_deleted_|TABLE)' | xargs`
echo "Dumping $DB tables: $TABLES"
mysqldump --defaults-group-suffix=$DB_GROUP --opt $DB $TABLES > backup-$DB.mysql
echo "Dumping $DB table structures: $TABLES_NODATA"
mysqldump --defaults-group-suffix=$DB_GROUP --opt --no-data $DB $TABLES_NODATA >> backup-$DB.mysql
fi
read -p "Backup Files? (y/N) " BACKUP_FILES
if [ "$BACKUP_FILES" == "y" ]; then
for FOLDER in "${FOLDERS[@]}"
do
echo "Backing up $WEBROOT/$FOLDER"
tar -czf backup-$FOLDER.tar.gz "$WEBROOT/$FOLDER"
done
fi
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment