Last active
February 27, 2020 09:13
-
-
Save davutkmbr/5a3c2601efc7c0f995c06b5a35f33b34 to your computer and use it in GitHub Desktop.
How to create hourly database backups in Plesk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment