Original source: github.com/ianneub/php_backup_s3/tree
This program will backup file paths and MySQL databases to Amazon's S3 storage cloud service.
I've used this program in production for about a year with no problems. But, your results may vary.
- Simple to use
- Backups all databases on a MySQL server
- Backups and compresses (using bzip2) directories and files
- Uses URL type storage keys, so it's easy to browse the backup bucket
- (optionally) Removes old backups according to a grandfather-father-son based schedule
- Copy the backup.dist.php file to a new file name, like backup.php
- Add your Amazon AWS access key and password in the backup.php file provided.
- Customize the files and database servers that are backed up.
- Upload to your server.
- Setup a cronjob to run the backups for you!
For example, create a file called /etc/cron.daily/backup and add this code to it:
#!/bin/bash
/usr/bin/php /path/to/script/backup.php
exit 0
NOTE: Make sure to set the /etc/cron.daily/backup file to be executable. Like this:
chmod +x /etc/cron.daily/backup
This set of scripts ships with three files:
- backup.php--This is an example of how to call the backup functions
- include/
- backup.inc.php--All the backup functions are in here
- S3.php--This is the library to access Amazon S3
A unique feature of this script is the way it will store (and eventually delete) old backups to conserve space, and yet maintain significant backup history. In this method you will have the following full backups:
- Everyday for the past two weeks (14 backups)
- Every saturday for the past 2 months (8 or 9 backups)
- First day of the month going back forever
This allows you to keep a very detailed history of your files during the most recent time, but progressively remove backups as time goes on to save space. This feature can be turned off if you want to store all your backups, all the time.
To disable this feature, comment out the following line from backup.inc.php:
deleteBackups($BACKUP_BUCKET);
My name is Ian. I wrote this small program to help backup my virtual machines hosted at various places. I figured someone might be able to make use of it, so I've published it as open source. I also wanted a way to store my version history, learn to use git, and do it for free. Thanks github!
- Add configuration documentation
- Comment code