If you have a website with important data, it is very important to take backups frequently. In most cases, hourly backup is very important.
I wrote a Bash Script for hourly backup for the database in Plesk.
Let’s move on to the steps.
$ mkdir /root/mysql_backups && cd /root/mysql_backups
$ touch backup.sh
$ chmod +x backup.sh
Replace line 3 with your own database names.
#!/bin/bash
BACKUP_DATABASES=(YOUR_DATABASE1 YOUR_DATABASE2 YOUR_DATABASE3)
BASE="/root/mysql_backups"
RECENT_BACKUPS=($BASE/*/)
NOW=`date +%Y-%m-%d-%H`
ONE_HOUR_AGO=`date -d "1 hour ago" +%Y-%m-%d-%H`
TWO_HOURS_AGO=`date -d "2 hours ago" +%Y-%m-%d-%H`
for i in "${RECENT_BACKUPS[@]}"; do
if [ "$BASE/$NOW/" = $i ] || [ "$BASE/$ONE_HOUR_AGO/" = $i ] || [ "$BASE/$TWO_HOURS_AGO/" = $i ]; then continue; fi;
rm -rf "$i"
done;
# Create today named folder if not exists.
[ ! -d "$BASE/$NOW" ] && mkdir "/$BASE/$NOW"
# Backup databases
for i in "${BACKUP_DATABASES[@]}"; do
/usr/sbin/plesk db dump $i | gzip > "$BASE/$NOW/${i}.sql.gz"
done;
$ vim backup.sh
Done! Now the script runs every hour and backup your selected databases.