This is a complex topic… One that there is no easy answer.
This issues are:
It needs to be as fast as possible or you client/users are going to scream at you…
You really can not use php for this. Or if you do, it will be a semi-automated manual process.
PHP script timeouts will keep you from doing a lot of stuff at one time. Plus there is the issues of the other files.
This is really a problem for system admin, not application development.
You are going to have to bite the bullet and write a DB specific backup and a file system backup.
MySql can create a fairly quick export of its table defs and data, so you will have to figure out how
to do this for the db you are using. You did not specify what you are using so, no one can give you
any help with that.
Then once you have your database backup you could basically zip the entire app and copy it to the new server,
upzip it, restore the database and fix up any details that have changed between servers.
I use mariadb (mysql) for my database.
I use backblaze for my offsite storage
I use duplicati to perform the backups
Google them to find out more.
Basicly I use mysqldump to create a file that contains all the info from the database.
This file is stored in my application tree so it gets backed up along with all files that my app creates while running.
Then I use duplicati to back it all up to Backblaze.
I guess I should test the whole restore process one day…
Probably the main thing you would need to figure out, is the db specific export and import.
#entirly unsupported example code. It may cause your server to melt. For example only.... YMMV....
echo Backing up example.com
#build sql filename and backup database
sql_file="`date +%y`_`date +%m`_`date +%d`example.sql"
rm -f $sql_file
mysqldump --user=root --password=password example > $sql_file
# copy all files to backblaze B2 using duplicati
duplicati-cli backup \
--backup-name=example_backup --dbpath=/root/.config/Duplicati/CNKYJHFH.sqlite \
--encryption-module=aes --compression-module=zip --dblock-size=5MB \
--passphrase="jkasDF$#%" --retention-policy="1W:1D,4W:1W,12M:1M" \
--disable-module=console-password-input --backup-test-samples=0 \
--log-level=Profiling --log-file=/var/log/duplicati.log \
echo Backing up example.com complete
Write several shell scripts to back up your MySQL db and the app content files, and run them periodically using cron. … This is a must job for the administrator of every web app.
As for your idea of “DBMS independent db backup”, I don’t think it’s very easy to implement. It won’t pay you the cost. And, you ain’t gonna need it. Although you will have to write a tool to convert your old MySQL db tables to your new DBMS ones when you need to change the underlying DBMS, it will be much easier and cheaper.