SCRIPT TO BACKUP ALL MYSQL DATABASES IN VESTACP

December 11, 2019   /   by Marco  / Categories :  Business
Business Legions - SCRIPT TO BACKUP ALL MYSQL DATABASES IN VESTACP

If you have multiple databases hosted on VestaCP the easiest way I found to backup all the databases is to use a script. The first thing you need to do is create a backup account in mySQL that has view only access to all the databases.

CREATE USER 'backupuser'@'localhost'
    IDENTIFIED BY 'xxx';
GRANT SELECT, SHOW VIEW, LOCK TABLES, RELOAD,
    REPLICATION CLIENT
    ON *.* TO 'backupuser'@'localhost';
FLUSH PRIVILEGES;

Then use this bash script. You can change the variables accordingly but the most important is the backup location, username and password which was created above:

#! /bin/bash

TIMESTAMP=$(date +”%F”)
BACKUP_DIR=”/web/backup/$TIMESTAMP”
MYSQL_USER=”xxx”
MYSQL=/usr/bin/mysql
MYSQL_PASSWORD=”xxx”
MYSQLDUMP=/usr/bin/mysqldump

mkdir -p “$BACKUP_DIR/mysql”

databases=`$MYSQL –user=$MYSQL_USER -p$MYSQL_PASSWORD -e “SHOW DATABASES;” | grep -Ev “(Database|information_schema|performance_schema)”`

for db in $databases; do
$MYSQLDUMP –force –opt –user=$MYSQL_USER -p$MYSQL_PASSWORD –databases $db | gzip > “$BACKUP_DIR/mysql/$db.gz”
done

Business Legions - SCRIPT TO BACKUP ALL MYSQL DATABASES IN VESTACP

Hopefully, this has helped someone.

DO YOU LIKE WHAT YOU'VE READ?
Join our subscription list and receive our content right in your mailbox. If you like to receive some Great deals our Freebies then subscribe now!

Our Sponsors

  • Follow us:

OTHER ARTICLES YOU MAY LIKE


DID YOU KNOW ABOUT THIS IN WINDOWS? CONNECT TO YOUR ANDROID PHONE

DID YOU KNOW ABOUT THIS IN WINDOWS? CONNECT TO YOUR ANDROID PHONE

Windows has quietly become an excellent companion to your Android phone. Thanks to Microsoft’s Phone Link app (formerly known as Your Phone), your PC can receive your mobile notifications, show your photos and messages, let you take calls, and even control media playback—without you lifting your phone. It’s brilliant for productivity and for keeping your […]

read more
CHATGPT USEFUL FEATURE: TEMPORARY CHAT

CHATGPT USEFUL FEATURE: TEMPORARY CHAT

Everyday use of ChatGPT naturally trains you to think in threads. You ask a question, you get an answer, you refine the prompt, and the conversation accretes context. It’s one of the reasons ChatGPT feels more like a companion than a search box: it remembers what you said so it can respond appropriately next time […]

read more

Like our Page