This plugin is for backing up a WordPress website to Amazon S3.
- Database backup
- Saves a local database dump with an obscure file name.
- Syncs local database with S3.
- Removes local copy to reduce wasted HDD space.
- Local development databases can be synced as well.
- Media library backup
- Two way sync of uploads folder and Amazon S3.
- This can be used for backing up live websites but also for syncing local development assets between developers.
- Offload S3 integration - Coming soon
- After media has been moving transferred, you can save the local meta data required for offload S3 to starting loading assets from S3.
This function syncs media, performs a DB backup and sync the database to S3.
Examples
wp backups backup
- backup media and database
wp backups backup --type=media
- This just syncs your media
wp backups backup --type=database
- Use this to dump the DB and sync with S3
Examples
wp backups development_sql_sync
- This checks the status of the remote development database
wp backups development_sql_sync --sync-direction=push
- This checks the status of the remote development database
- Then provides the option to overwrite the remote database with what is available locally
wp backups development_sql_sync --sync-direction=pull
- This checks the status of the remote development database
- Then provides the option to overwrite the local database with what is available on S3
1. Add the Wordpress plugin to your composer file by navigating to your project and running this inside a terminal:
composer require atomicsmash/backups "*"
Commit the changes to your local composer file.
And these constants to your wp-config file:
define('BACKUPS_S3_REGION','eu-west-2'); //London
define('BACKUPS_S3_ACCESS_KEY_ID','');
define('BACKUPS_S3_SECRET_ACCESS_KEY','');
You can obtain these details by creating an IAM user. Here is our guide on how to setup an IAM Amazon user and get the access and secret key that you need.
If you know the name of the bucket you would like to sync with, you can hard this by adding:
define('BACKUPS_S3_BUCKET','');
Commit the changes to your config.
Now activate the plugin on whichever site you would like backup. This can be done via the admin interface, or by running:
wp plugin activate backups
If you want to backup a live website, chances are you will need to SSH into the server.
To test the connection to S3 run:
wp backups check_credentials
If there is an issue, please check your credentials are being loaded and are correct.
wp backups create_bucket <bucket_name>
bucket_name
is usually the address of the site you are currently working on ('website.local'). For example:
wp backups create_bucket mywebsite.co.uk
Running the above command will ask the question: Create bucket? [y/n]
- supply 'y' to continue.
This will then create a bucket called "mywebsite.co.uk.backup" and select it ready for use.
To start the first backup manually,
wp backups backup
Depending on how often you backup your website, the SQL files will start to build up quickly. You can setup an S3 folder lifecycle to auto-delete files older than X number of days.
wp backups setup_autodelete_sql <number_of_days>
We usually usually retain backups for 30 days, so we would run:
wp backups setup_autodelete_sql 30
To get the backup command to run on a regular basis, you need to setup a cron job. Use something similar to this:
/usr/local/bin/wp backups backup --path=/path/to/www.website.co.uk/
If you are using composer in your project then your WordPress core files might be inside a subfolder, please modify the path to reflect this. The cron job would look like this:
/usr/local/bin/wp backups backup --path=/path/to/www.website.co.uk/wp
If you are using forge, then simply add to the server scheduling panel:
Also, if you are using Capistrano, don't forget to add current
to the
/usr/local/bin/wp backups backup --path=/path/to/www.website.co.uk/current/wp
Are you receiving an error similar to PHP Fatal error: Uncaught Error: Class 'Aws\S3\S3Client' not found in /path/to/file
Make sure you are requiring your autoload.php generated by composer. We usually add this to the top of our wp-config file:
require( dirname( __FILE__ ) . '/vendor/autoload.php' );
- Backup stats
- Added 'restore' functionality
= 0.1.2 =
- Added more exceptions for downloading data/development sql files
= 0.1.1 =
- Added exception for downloading data/development sql files
= 0.1.0 =
- Added local development database backups
- Added better plugin development detection by looking for the existence of an vendor/autoload.php file
- There is a new BACKUPS_S3_BUCKET constant to hard code the preferred bucket
= 0.0.5 =
- Updated readme
= 0.0.4 =
- Improved UX when creating a bucket
- FIXED issue with syncing DB backups back to local machine from S3
= 0.0.3 =
- Added offload S3 functionality
- Added setup guide
- Added lifecycle addition for SQL folder
= 0.0.2 =
- Simplified media transferring
= 0.0.1 =
- Project renamed from log-flume to 'Backups'
- Added database backup functionality