Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

commandantp's avatar

Automatically backup the database with DO & Forge

Hi guys,

Any recommendation for automatic back ups of the database content? I am using Digital Ocean & Forge.

How do you handle it and what has worked best so far?

Thanks

0 likes
5 replies
henrique's avatar

I think it's interesting to clear one thing up, Digital Ocean offers Droplet automatic (and manual) backup, but you shouldn't rely on it for the data backup (auto: because it runs just once each 3 days or so, manual: because you may forget and it won't run as often as you would want). DO's backup should be used only for having a fast way to recreate your droplet if anything goes wrong, then on top of that you restore your database, files or anything that changed between the backup and the failure.

Right now I'm using a custom .sh script:

#!/bin/sh

echo '\n'
echo '******************** BEGIN ********************'
echo "Begin $(date)\n"

FILE=backup_`date +%Y-%m-%d_%H-%M`.sql.gz

MYSQL_PASSWORD="mysqlpassword"

cd ~/backups
mysqldump -u mysqluser -p"${MYSQL_PASSWORD}" mysqldatabase | gzip > ${FILE}
echo "Backup done! Sending it to backup server\n"
scp ${FILE} user@host:~/backups/database/
md5sum ${FILE}
rm ${FILE}

echo "\nEnd $(date)"
echo '********************* END *********************'

That runs on cron 4 times a day, but I would like to change this to incremental backups, making 1 backup per day + incremental backups each... I don't know, hour? But I didn't figure a nice way to do this :(

commandantp's avatar

ummm, ok thanks guys. So from where I see it, there is no "best practice" or way to do it? Many options...

bashy's avatar

Really depends on how secure/stable/scalable you want it. Obviously you wouldn't use this type of thing for a client's or corperate website. Something like R1Soft Backup is a purposely built continuous backup solution.

Please or to participate in this conversation.