#!/bin/bash
#----------------------------------------
# OPTIONS
#----------------------------------------
USER='root' # MySQL User
PASSWORD='xxxxxxx' # MySQL Password
DAYS_TO_KEEP=30 # 0 to keep forever
GZIP=1 # 1 = Compress
TODAY=`date +"%d%m%Y"`
BACKUP_PATH='/var/www/BKP'
#----------------------------------------
# Create the backup folder
if [ ! -d $BACKUP_PATH ]; then
mkdir -p $BACKUP_PATH
fi
cd /var/www/
zip -r gc-solutions.net_"$TODAY".zip /var/www/gc-solutions.net
mv gc-solutions.net_"$TODAY".zip ${BACKUP_PATH}/
# Get list of database names
databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "|" | grep -v Database`
for db in $databases; do
if [ $db == 'information_schema' ] || [ $db == 'performance_schema' ] || [ $db == 'mysql' ] || [ $db == 'sys' ]; then
echo "Skipping database: $db"
continue
fi
date=$(date -I)
# if [ "$GZIP" -eq 0 ] ; then
echo "Backing up database: $db without compression"
mysqldump -u $USER -p$PASSWORD --databases $db > $BACKUP_PATH/$db-"$TODAY".sql
#else
echo "Backing up database: $db with compression"
mysqldump -u $USER -p$PASSWORD --databases $db | gzip -c > $BACKUP_PATH/$db-"$TODAY".sql.gz
#fi
done
# Delete old backups
if [ "$DAYS_TO_KEEP" -gt 0 ] ; then
echo "Deleting backups older than $DAYS_TO_KEEP days"
find $BACKUP_PATH/* -mtime +$DAYS_TO_KEEP -exec rm {} \;
fi
Website backup script batabase and home folder Print
Created by: Rajesh Mehta
Modified on: Fri, 4 Sep, 2020 at 5:31 PM
Did you find it helpful? Yes No
Send feedbackSorry we couldn't be helpful. Help us improve this article with your feedback.