MySQL Backup Script with PHP and S3
Tonight I update my previous script to backup a MySQL database. I am a web developer and not a system administrator, but I have to wear multiple hates and act like a system administrator. But I hate it! So when I go out on Google and look for system admin code it all is written in perl or bash, which yeah I know it's easy but I'm just not as familiar with. So I always want to write my scripts in pure PHP which I could write in my sleep. So here is my attempt at a database backup script that will not interupt my high traffic site too much (thanks to mysqlhotcopy), will be zipped up, and sent over to Amazon S3 for that secure sleep-at-night feeling an off-site backup brings!
I have expanded upon it to make it more customizable and added some bells and whistles. I also added a lot of comments in the code. The features include...
- Backup one more more databases with mysqlhotcopy
- Gzip the backup and store locally
- Optionally upload the backup to Amazon S3 account using the s3-bash script. You will need to put a file called secret.txt that contains ONLY your s3 secret key in the same folder.
- Optionally delete yesterday's backup from S3
- Optionally delete the local backups
- Optionally email a report to yourself including the length of time the backup took and the size of the gzipped backup file
Requirements...
- Obviouslly you need to be running a LAMP system (Linux, Apache, MySQL, PHP)
- Must have cURL installed on your server
- Need to download this S3.php class and place it in the same directory.
The code:
Comments