Automatic database backup generation for VPS Plesk

Note! This article encompasses only MySQL database backup via Plesk.

Plesk in Linux does not provide the option to generate backups for MySQL databases via Backup Manager. The only way to get a backup is to use the export option via phpMyAdmin. Please click here for details.

The only way to automate the backup process is to configure a CRON for the following script.

#!/bin/bash
# Set the datestamp, login credentials and backup directory
export date=$(date +\%Y\%m\%d)
export creds="-uadmin -p`cat /etc/psa/.psa.shadow`"
export backupdir="/mysqlbackup"
# delete week old files
find ${backupdir}/ -regex '.*.dump.gz' -mtime +4 -exec rm {} \;
# dump databases to the backupdir
echo "show databases;" | mysql ${creds} | egrep -v ^Database$ | \
awk '{print "mysqldump ${creds} "$1" | \
gzip > ${backupdir}/db-"$1"-${date}.dump.gz"}' | \
sh


As per the above script, backup will be created under the /mysqlbackup directory (create it manually on your server) and the name of the backup will be as db-dbName-yyyymmdd.dump.gz. Furthermore, upon execution the script will check for old backups and delete them automatically depending upon the value of mtime you want to specify.
  • Plesk, VPS
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

PHP require, require_once errors

If you an error that looks like one of these... Warning:...

How to drop tables from a database in phpMyAdmin?

This article will demonstrate how to drop (permanently delete) tables from a database in...

Optimizing Magento

Magento is a very popular eCommerce application. It offers a great deal of customization and...

Optimizing Joomla

Joomla is a popular CMS that is highly extensible and customizable. The following are suggestions...

Optimizing Wordpress

Wordpress is currently one of the most popular blogging/CMS applications. Here are some ideas for...

Powered by WHMCompleteSolution