This technique has been superseded by the new cPanel/WHM backup tool. The process is still interesting in that it shows you how to create hooks, but is no longer needed since it function is now built in.
If you have a WHM/cPanel based server, then you probably already have a daily backup running that keeps daily, weekly and monthly backups in another folder. But this does not help if the server disappears – you also need an offsite backup and Amazons S3 is perfect for this.
The good news is that there already exists a ‘hook’ that is run after an cPanel backup that we can use to do this.
Note: The functionality already exists to FTP backups to an external FTP server.
First you need to set up backups in WHM
- Log into WHM
- Select Backups -Configure Backup
- Backup Status = “Enabled”
- Select time frames and other options as desired.
- Backup Destination = “/backup”
Now we need to write our hook script. SSH into your server as root.
touch /scripts/postcpbackup chmod +x /scripts/postcpbackup vim /scripts/postcpbackup
add these lines. You will need to get your amazon keys and setup a target bucket from the AWS site
`export AWS_ACCESS_KEY_ID=xxx export AWS_SECRET_ACCESS_KEY=xxx s3sync -v -r --delete /backup/cpbackup/daily/ bucketname:daily/`
And all done.
You can manually run the backup with
and check that it has synchronised your daily backup to the S3 bucket when finished.
As a final note,
- This backup does every single setting, file and log file for a cPanel account and so should be fully recoverable.
- It only keeps the last copy (for disaster recovery – ie. your server explodes) and not older copies (for error recovery). These are kept on the server itself depending on how you configured the WHM backup.