- Edited
FYI this is not my script so all the credit to this fellow who wrote it and shared.
I had been looking for a simple, current, working script for backing up to remote storage. Also a documented way to restore from said backup. I found the following which works perfect, I have tested. Its simple and works well. There is no restore script but I am including the steps below. You could easily script it but restores don't happen as often as backups so maybe not a big deal.
You will need to adjust the script's storage piece to fit your own purposes but its just using rclone and is thus simple stuff.
https://github.com/josephcy95/wpbackup
Restore steps
cd to /var/www
- rename current domain "domain.com" -> "domain.com-old"
- rclone copy remote:sites/domain.com domain.com
- tar --zstd -xvf backup-file.tar.zst
cd to /var/www/domain.com/htdocs
wp db reset --yes --allow-root
wp db import /var/www/domain.com/2024-11-09_20-37-domain.com.sql --allow-root
a. this will restore db files to /var/lib/mysql/domain.com…etc
b. db name is stored in wp-config.php
rm backup files from /var/www/domain.com