Updated plesk-backup.sh

* Added mySQL query to get domain name
    * Added mySQL query to get www_root
    * Named Archive using domain name
This commit is contained in:
Matthew McKinnon 2018-05-05 12:29:08 +10:00
parent a82c5cd068
commit dd946b33c4

View File

@ -45,23 +45,24 @@ startlogging
rotate_backups rotate_backups
#Backup www_root website files #Backup website files
WWW_ROOT=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select www_root from psa.hosting; ') # Get domain ID
IDS=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select id from psa.domains, psa.hosting where id = dom_id order by id;')
for domain in $WWW_ROOT; do #Use ID to get domain name and www_root folders and create archive using domain name.
ARCHIVE=$(echo $domain | awk -F/ '{print $6}';) for ID in $IDS; do
echo "$(date) [MESSAGE] Creating archive of $domain" >> $LOGFILE DOMAIN_NAME=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select name from psa.domains,psa.hosting where id = '$ID' AND dom_id ='$ID' order by id;')
zip -rq $BACKUPDIR/$ARCHIVE.$BAKDATE.zip $domain WWW_ROOT=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e 'select www_root from psa.domains,psa.hosting where id = '$ID' AND dom_id ='$ID' order by id;')
echo "$(date) [MESSAGE] Creating archive of $DOMAIN_NAME" >> $LOGFILE
zip -rq $BACKUPDIR/$DOMAIN_NAME.$BAKDATE.zip $WWW_ROOT
done done
#Backup databases #Backup databases
databases=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e "SHOW DATABASES;" | tr -d "| " | grep -v Database) databases=$(MYSQL_PWD=$(cat /etc/psa/.psa.shadow) mysql -sN -uadmin -e "SHOW DATABASES;" | tr -d "| " | grep -v Database)
#echo $databases;
for db in $databases; do for db in $databases; do
if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "apsc" ]] && [[ "$db" != "horde" ]] && [[ "$db" != phpmyadmin_* ]] && [[ "$db" != "psa" ]] && [[ "$db" != "roundcubemail" ]] ; then if [[ "$db" != "information_schema" ]] && [[ "$db" != "performance_schema" ]] && [[ "$db" != "mysql" ]] && [[ "$db" != _* ]] && [[ "$db" != "apsc" ]] && [[ "$db" != "horde" ]] && [[ "$db" != phpmyadmin_* ]] && [[ "$db" != "psa" ]] && [[ "$db" != "roundcubemail" ]] ; then
echo "$(date) [MESSAGE] Dumping $db to sql file" >> $LOGFILE echo "$(date) [MESSAGE] Dumping $db to sql file" >> $LOGFILE