Created
March 3, 2014 20:44
-
-
Save corbanb/9334260 to your computer and use it in GitHub Desktop.
Backup database to S3 bucket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $date = date("Y-m-dTH:i:s"); | |
| $file = 'db.backup.' . $date . '.sql.gz'; | |
| error_log("Database Backup Started - " . $file); | |
| exec('touch ' . $file); | |
| exec('chmod 600 ' . $file); | |
| exec('mysqldump -u user --password="password" --add-drop-table --single-transaction database_name | gzip > ' . $file); | |
| exec('aws s3 mv ' . $file . ' s3://cdn.domain.com/db-backups/ --region us-west-1 --endpoint-url http://s3.amazonaws.com --acl bucket-owner-full-control'); | |
| error_log("Database Backup Complete- " . $file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment