SCRIPT TO BACKUP ALL MYSQL DATABASES IN VESTACP
December 11, 2019 / by Marco / Categories : BusinessIf 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
Hopefully, this has helped someone.
OTHER ARTICLES YOU MAY LIKE
POWERFUL REFERRAL PROGRAM TOOL
Businesses of all sizes are constantly seeking new and innovative ways to grow their customer base and increase brand awareness. With the rise of social media and the reliance on word-of-mouth marketing, referral programs have become an essential tool for companies looking to expand their reach. However, managing a successful referral program can be a […]
read moreCYBER SECURITY PLATFORM FOR YOUR BUSINESS
Cyber security has become a top priority for individuals and organizations alike. With the ever-evolving threat of cyber attacks, it is imperative to have a strong and reliable security platform in place to protect sensitive information and data. That’s where Bleach Cyber comes in. As a leading cyber security platform, Bleach Cyber is dedicated to […]
read more