Skip to content

Instantly share code, notes, and snippets.

@corbanb
Created March 3, 2014 20:44
Show Gist options
  • Select an option

  • Save corbanb/9334260 to your computer and use it in GitHub Desktop.

Select an option

Save corbanb/9334260 to your computer and use it in GitHub Desktop.
Backup database to S3 bucket
<?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